/**
 * @file lv_demo_widgets.c
 *
 */

/*********************
 *      INCLUDES
 *********************/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "lcd.h"
#include "lvgl.h"
#include "lv_custom_list.h"
#include "lv_custom_gui.h"
#include "src/hal/lv_hal_disp.h"

#if 1

#if LV_MEM_CUSTOM == 0 && LV_MEM_SIZE < (38ul * 1024ul)
    #error Insufficient memory for lv_demo_widgets. Please set LV_MEM_SIZE to at least 38KB (38ul * 1024ul).  48KB is recommended.
#endif

#define HEART_WIDTH     240
#define HEART_XPOS      120
#define HEART_YPOS      80
#define HEART_COLOR     (lv_color_make(233, 88, 145))
#define HEART_COLOR_BG  (lv_color_make(106,90,205))

#define OUTLINE_W      	27 //电池图标宽度
#define OUTLINE_H      	14 //电池图标高度

#define TILES_WIDTH     256
#define TILES_HIGHT     256

#define FEATRUE_ROTATION    (1<<0)

/*********************
 *      DEFINES
 *********************/
LV_FONT_DECLARE(lv_custom_icon)

#ifndef float32_t
typedef float float32_t;
#endif

extern uint32_t  diff;
extern uint16_t  uart6_cnt[2];
extern float32_t longitude;
extern float32_t latitude;
extern float32_t longitude_gjc;
extern float32_t latitude_gjc;
/**********************
 *      TYPEDEFS
 **********************/
typedef enum {
    DISP_SMALL,
    DISP_MEDIUM,
    DISP_LARGE,
} disp_size_t;

typedef enum
{
    PAGE_NULL = -1,
    /* 假设有两个页面：LOGO和MAIN，增加页面后自行在此添加对应的枚举类型 */
    PAGE_HOME,
    PAGE_HEART,
    PAGE_CLOCK,
    PAGE_CALENDAR,
    PAGE_HORIZON,
    PAGE_LOCATION,
    PAGE_SETTING,
}PAGE_ID;

typedef void(*page_init_handle)(void*self);

typedef struct
{
    lv_obj_t* panel;
    lv_obj_t* bat_outline;  //battery外轮廓线
    lv_obj_t* bat_subbody;  //battery右侧电极
    lv_obj_t* bat_voltage;  //battery电量百分比
    lv_obj_t* bat_backdrop; //battery电量背景填充
    lv_obj_t* bat_charge;   //battery充电状态
    lv_obj_t* gps_signal;   //GPS信号状态
    lv_obj_t* rl_clock;     //实时时间
    lv_obj_t* status[2];    //预留x1
}UI_Status_t;

typedef struct PageStruct
{
    struct list_head node;
    uint8_t   page_id;
    uint8_t   inited;
    uint8_t   features;
    lv_disp_rot_t rotation;
    lv_obj_t* screen;
    page_init_handle init_handler;  //页面中所有组件的初始化函数,以screen为父对象
    lv_timer_t* timer;
    //lv_obj_t *status[5];
    UI_Status_t status_bar;
    uint32_t  obj_num;
    lv_obj_t* objs[8];
}PageStruct_t;

/**********************
 *  STATIC PROTOTYPES
 **********************/
static void home_create(void* self);
static void heart_create(void* self);
static void clock_create(void* self);
static void calendar_create(void* self);
static void horizon_create(void* self);
static void location_create(void* self);
static void setting_create(void* self);
static void other_create(void* self);

//
static void status_bar_update(PageStruct_t* page);

//event callback
static void calendar_event_cb(lv_event_t * e);


/**********************
 *  STATIC VARIABLES
 **********************/
static lv_obj_t * tv;
static lv_obj_t * calendar;
static lv_style_t style_text_muted;
static lv_style_t style_title;
static lv_style_t style_normal;
static lv_style_t style_icon;
static lv_style_t style_arc;
static lv_style_t style_charge;
static lv_style_t style_line;
static lv_style_t style_comb; //创建组合体style
static lv_style_t style_batval;

static const lv_font_t* font_large;
static const lv_font_t* font_normal;

static uint32_t USER_Event_ROTATE;
//static uint32_t USER_Event_CLOCK;
static uint32_t USER_Event_STATBAR;

//HeartBeat
static int nHeartFrames = 0;
static int nHeartZoom = 1;
//static lv_color_int_t buffer[HEART_WIDTH][HEART_WIDTH];
static lv_color_t* m_HeartBuf = NULL;
static lv_color_t  m_ClearBuf[8];
static lv_color_t  m_colorBack;
static lv_color_t  m_colorPoint;

//Clock
static NmeaTime_T m_curtime = { 2024, 00, 00, 00, 00, 00 };
static uint8_t    m_today = 0;
static uint8_t    m_second = 0;
static uint8_t    m_clocksync = 0;

//horizon
static int32_t    m_angle = 0;
static int32_t    m_pitch = 0;
static int32_t    m_roll  = 0;

//location
static int location_zoom = 13; //default
static int tiles_pos_x[2] = { 0, 13348 * 256 +  78 };
static int tiles_pos_y[2] = { 0,  6845 * 256 + 105 };

//StatusBar
uint32_t          m_volval = 0;
static uint16_t   m_batFlag = 0;
static uint8_t    m_charge = 0;
static uint8_t    m_voltage = 52;

#define THEME_COLOR_MAX     4
static int m_colorSel = 0;
static lv_color_t  m_colorTheme[][THEME_COLOR_MAX] =
{
    //seconed                         default                        fousce
    { LV_COLOR_MAKE(0xCE, 0x93, 0xBF), LV_COLOR_MAKE(0xA6, 0x56, 0x9D),LV_COLOR_MAKE(0x8A, 0x18, 0x74), LV_COLOR_MAKE(0,0,0) },
    { LV_COLOR_MAKE(0xe6, 0x77, 0x62), LV_COLOR_MAKE(0xD2, 0x47, 0x35),LV_COLOR_MAKE(0xC8, 0x16, 0x1D), LV_COLOR_MAKE(0,0,0) },
    { LV_COLOR_MAKE(0xf0, 0x91, 0xa0), LV_COLOR_MAKE(0xdc, 0x6b, 0x82),LV_COLOR_MAKE(0xc2, 0x51, 0x60), LV_COLOR_MAKE(0,0,0) },
    { LV_COLOR_MAKE(0x87, 0xc0, 0xca), LV_COLOR_MAKE(0x5a, 0xa4, 0xae),LV_COLOR_MAKE(0x3d, 0x8e, 0x86), LV_COLOR_MAKE(0,0,0) },
};

static lv_group_t*   group_default = NULL;
static struct list_head page_list = { &page_list, &page_list };
static PAGE_ID       page_subid = PAGE_HEART - 1;
static PageStruct_t* page_focus = NULL;
static lv_disp_rot_t m_rotation = LV_DISP_ROT_NONE;

static PageStruct_t page_home = {
    .page_id = PAGE_HOME,
    .rotation = LV_DISP_ROT_NONE,
    .features = FEATRUE_ROTATION,
    .init_handler = home_create,   //初始化页面中的各个组件的函数
    .screen = NULL,
    .timer = NULL,
    .obj_num = 0,
};

static PageStruct_t page_heart = {
    .page_id = PAGE_HEART,
    .rotation = LV_DISP_ROT_NONE,
    .features = FEATRUE_ROTATION,
    .init_handler = heart_create,   //初始化页面中的各个组件的函数
    .screen = NULL,
    .timer = NULL,
    .obj_num = 0,
};

static PageStruct_t page_clock = {
    .page_id = PAGE_CLOCK,
    .rotation = LV_DISP_ROT_NONE,
    .features = FEATRUE_ROTATION,
    .init_handler = clock_create,   //初始化页面中的各个组件的函数
    .screen = NULL,
    .obj_num = 0,
};

static PageStruct_t page_calendar = {
    .page_id = PAGE_CALENDAR,
    .rotation = LV_DISP_ROT_NONE,
    .features = FEATRUE_ROTATION,
    .init_handler = calendar_create,   //初始化页面中的各个组件的函数
    .screen = NULL,
    .timer = NULL,
    .obj_num = 0,
};

static PageStruct_t page_horizon = {
    .page_id = PAGE_HORIZON,
    .rotation = LV_DISP_ROT_NONE,
    .features = 0,
    .init_handler = horizon_create,   //初始化页面中的各个组件的函数
    .screen = NULL,
    .timer = NULL,
    .obj_num = 0,
};

static PageStruct_t page_location = {
    .page_id = PAGE_LOCATION,
    .rotation = LV_DISP_ROT_NONE,
    .features = FEATRUE_ROTATION,
    .init_handler = location_create,   //初始化页面中的各个组件的函数
    .screen = NULL,
    .timer = NULL,
    .obj_num = 0,
};

static PageStruct_t page_setting = {
    .page_id = PAGE_SETTING,
    .rotation = LV_DISP_ROT_NONE,
    .features = FEATRUE_ROTATION,
    .init_handler = setting_create,   //初始化页面中的各个组件的函数
    .screen = NULL,
    .timer = NULL,
    .obj_num = 0,
};

/************************************************************************/
/* HeartBeat Draw                                                       */
/************************************************************************/
static int GetRandVal(int nMax)
{
    int val = 0;
    for (int i = 0; i < 6; i++)
        val += (rand() % nMax);
    val /= 6;
    val -= (nMax / 2);
    if (val < 0) val *= -1;
    return val * 2;
}

static void Diffuse(lv_obj_t* canvas, int r, int x, int y, int dx, int dy)
{
    int i;
    int xn, yn;
    //double k = 1.0;
    double sinx = 1.0 * dy / r;
    double cosx = 1.0 * dx / r;
    //k = 1.0 * dy / dx;
    for (i = 0; i < 4; i++)
    {
        int d;
        d = GetRandVal(40);
        xn = (r - d) * cosx;
        yn = (r - d) * sinx;

        //m_HeartBuf[((y + yn)* HEART_WIDTH) + (x + xn)] = 1;
        lv_canvas_set_px(canvas, x + xn, (y + yn), m_colorPoint);
    }
    for (i = 0; i < 2; i++)
    {
        int d;
        d = GetRandVal(40);
        xn = (r + d) * cosx;
        yn = (r + d) * sinx;

        if (y + yn >= HEART_WIDTH || y + yn < 0)
            continue;

        //m_HeartBuf[((y + yn)* HEART_WIDTH) +( x + xn)] = 1;
        lv_canvas_set_px(canvas, x + xn, (y + yn), m_colorPoint);
    }
}

/*     \ 3 | 2 /
 *      \  |  /
 *    4  \ | /   1
 * - ------+----------> X
 *    5  / | \   8
 *      /  |  \
 *     / 6 | 7 \
 *         Y
 */
static void DrawCircle(lv_obj_t* canvas, int x, int y, int r, int mask)
{
    int a, b;
    int di;
    a = 0;
    b = r;
    di = 3 - (r << 1); //判断下个点位置的标志
    while (a <= b)
    {
        //if (mask & 0x02) m_HeartBuf[((y - b)*HEART_WIDTH)+ x + a] = 1; //2
        //if (mask & 0x40) m_HeartBuf[((y + b)*HEART_WIDTH)+ x + a] = 1; //7
        //if (mask & 0x80) m_HeartBuf[((y + a)*HEART_WIDTH)+ x + b] = 1; //8
        //if (mask & 0x01) m_HeartBuf[((y - a)*HEART_WIDTH)+ x + b] = 1; //1
        //if (mask & 0x20) m_HeartBuf[((y + b)*HEART_WIDTH)+ x - a] = 1; //6
        //if (mask & 0x10) m_HeartBuf[((y + a)*HEART_WIDTH)+ x - b] = 1; //5
        //if (mask & 0x04) m_HeartBuf[((y - b)*HEART_WIDTH)+ x - a] = 1; //3
        //if (mask & 0x08) m_HeartBuf[((y - a)*HEART_WIDTH)+ x - b] = 1; //4

        if (mask & 0x02) lv_canvas_set_px(canvas, x + a, (y - b), m_colorPoint); //2
        if (mask & 0x40) lv_canvas_set_px(canvas, x + a, (y + b), m_colorPoint); //7
        if (mask & 0x80) lv_canvas_set_px(canvas, x + b, (y + a), m_colorPoint); //8
        if (mask & 0x01) lv_canvas_set_px(canvas, x + b, (y - a), m_colorPoint); //1
        if (mask & 0x20) lv_canvas_set_px(canvas, x - a, (y + b), m_colorPoint); //6
        if (mask & 0x10) lv_canvas_set_px(canvas, x - b, (y + a), m_colorPoint); //5
        if (mask & 0x04) lv_canvas_set_px(canvas, x - a, (y - b), m_colorPoint); //3
        if (mask & 0x08) lv_canvas_set_px(canvas, x - b, (y - a), m_colorPoint); //4

        if (mask & 0x02)Diffuse(canvas, r, x, y, 0 + a, 0 - b);
        if (mask & 0x40)Diffuse(canvas, r, x, y, 0 + a, 0 + b);
        if (mask & 0x80)Diffuse(canvas, r, x, y, 0 + b, 0 + a);
        if (mask & 0x01)Diffuse(canvas, r, x, y, 0 + b, 0 - a);
        if (mask & 0x20)Diffuse(canvas, r, x, y, 0 - a, 0 + b);
        if (mask & 0x10)Diffuse(canvas, r, x, y, 0 - b, 0 + a);
        if (mask & 0x04)Diffuse(canvas, r, x, y, 0 - a, 0 - b);
        if (mask & 0x08)Diffuse(canvas, r, x, y, 0 - b, 0 - a);

        a++;
        //使用Bresenham算法画圆
        if (di < 0)di += 4 * a + 6;
        else {
            di += 10 + 4 * (a - b);
            b--;
        }
    }
}

static void DrawCircle2(lv_obj_t* canvas, int x, int y, int r, int mask)
{
    int a, b;
    int di;
    a = 0;
    b = r;
    di = 3 - (r << 1); //判断下个点位置的标志
    while (a <= b)
    {
        if (mask & 0x02) Diffuse(canvas, r, x, y, 0 + a, 0 - b);
        if (mask & 0x40) Diffuse(canvas, r, x, y, 0 + a, 0 + b);
        if (mask & 0x80) Diffuse(canvas, r, x, y, 0 + b, 0 + a);
        if (mask & 0x01) Diffuse(canvas, r, x, y, 0 + b, 0 - a);
        if (mask & 0x20) Diffuse(canvas, r, x, y, 0 - a, 0 + b);
        if (mask & 0x10) Diffuse(canvas, r, x, y, 0 - b, 0 + a);
        if (mask & 0x04) Diffuse(canvas, r, x, y, 0 - a, 0 - b);
        if (mask & 0x08) Diffuse(canvas, r, x, y, 0 - b, 0 - a);

        a++;
        //使用Bresenham算法画圆
        if (di < 0)di += 4 * a + 6;
        else {
            di += 10 + 4 * (a - b);
            b--;
        }
    }
}

static void DrawHeart(lv_obj_t* canvas)
{
    int y;
    int R = 40 + nHeartFrames;
    int Y = HEART_YPOS - nHeartFrames / 2;
    int X = HEART_XPOS;

    lv_canvas_fill_bg(canvas, m_colorBack, LV_OPA_TRANSP);
    //for (x = 0; x < LV_CANVAS_BUF_SIZE_INDEXED_1BIT(HEART_WIDTH,HEART_WIDTH); x++)
    //{
    //    m_HeartBuf[x] = 0;
    //}

    DrawCircle(canvas, X + R, Y, R, 0x0f); //右上半圆
    DrawCircle(canvas, X - R, Y, R, 0x0f); //左上半圆
    DrawCircle(canvas, X + 0, Y, R * 2, 0x90); //左右中间1/4圆
    DrawCircle2(canvas, X + 0, Y, R / 3, 0xf0); //补充顶尖扩散

    /* 底部尖角 */
    for (y = (R * 14 + 5) / 10; y < (R * 28 + 25) / 10; y++)
    {
        //m_HeartBuf[((Y + y - 1) * HEART_WIDTH) + X + (((R * 28 + 15) / 10 - y))] = 1;
        //m_HeartBuf[((Y + y - 1) * HEART_WIDTH) + X - (((R * 28 + 15) / 10 - y))] = 1;
        lv_canvas_set_px(canvas, X + ((R * 28 + 15) / 10 - y), (Y + y - 1), m_colorPoint);
        lv_canvas_set_px(canvas, X - ((R * 28 + 15) / 10 - y), (Y + y - 1), m_colorPoint);
    }

    int max = (R * 14 + 5) / 10;
    for (y = 0; y < max + 8; y++)
    {
        Diffuse(canvas, R * 2, X - y, Y + y,  max, max);
        Diffuse(canvas, R * 2, X + y, Y + y, -max, max);
    }
}

/************************************************************************/
/* Page Manager                                                         */
/************************************************************************/
static PageStruct_t* page_find(PAGE_ID page_id)
{
    PageStruct_t* next = NULL;
    list_for_each_entry(next, &page_list, node, PageStruct_t)
    {
        if (next->page_id == page_id)
            return next;
    }

    return NULL;
}

static void page_add(PageStruct_t* page)
{
    PageStruct_t* node = page_find(page->page_id);
    if (node != NULL)
    {
        LV_LOG_WARN("page has been added!\r\n");
        return;
    }

    page->inited = 0;
    page->rotation = LV_DISP_ROT_NONE;
    list_add_tail(&page->node, &page_list);
    {
        LV_LOG_WARN("page %d adds successfully!\r\n", page->page_id);
    }
}

static PageStruct_t* page_create(uint8_t id)
{
    PageStruct_t* page = page_find(id);
    if (page != NULL)
    {
        page->screen = lv_obj_create(NULL);
        /* 每个页面的大小与LCD屏幕大小对应 */
        lv_obj_set_size(page->screen, LV_HOR_RES, LV_VER_RES);
        page->init_handler(page);
    }

    return page;
}

static void page_load_objs(PageStruct_t* page)
{
    lv_group_remove_all_objs(group_default);

    for (int i = 0; i < page->obj_num; i++) {
        if (page->objs[i] == NULL)
            continue;
        lv_group_add_obj(group_default, page->objs[i]);
    }
    if (page->page_id == PAGE_HEART)
    {
       m_HeartBuf = lv_mem_alloc(LV_CANVAS_BUF_SIZE_INDEXED_1BIT(HEART_WIDTH, HEART_WIDTH));
    }
    if (page->page_id == PAGE_HOME &&  page_subid < page->obj_num)
    {
        lv_group_focus_obj(page->objs[page_subid]);
    }
    if (page->timer)
    {
        lv_timer_resume(page->timer);
    }
}

static void page_callback(PAGE_ID arg, lv_scr_load_anim_t animation, bool fade)
{
    uint8_t id = (uint8_t)arg;
    PageStruct_t* page = page_find(id);
    lv_obj_t* act_scr = lv_scr_act();
    lv_disp_t* d = lv_obj_get_disp(act_scr);

    if (page == NULL)
    {
        return;
    }

    if (d->prev_scr == NULL && (d->scr_to_load == NULL || d->scr_to_load == act_scr))
    {
        /* 根据待切换屏幕的page_id找到其结构体 */
        page = page_find(id);
        if (page == NULL)
            return;

        /* 如果屏幕中的组件被删除了,重新创建 */
        if (page->screen == NULL)
        {
            page->obj_num = 0;
            page_create(id);
            if (page->screen == NULL)
                return;
        }
        else
        {
            status_bar_update(page);
        }

        if ((page->features & FEATRUE_ROTATION) && (lv_disp_get_rotation(NULL) != page->rotation))
        {
            lv_obj_set_size(page->screen, LV_HOR_RES, LV_VER_RES);
            page->init_handler(page);
            page->rotation = lv_disp_get_rotation(NULL);
        }
        page_focus = page;
        page_load_objs(page);
        if (page->page_id == PAGE_LOCATION)
            lv_group_set_editing(lv_group_get_default(), true);

        /* 加载新页面:这里固定了animation的时间 */
        lv_scr_load_anim(page->screen, animation, fade?300:50, 50, false);
    }
}

static void page_user_event_cb(lv_event_t* event)
{
    uint32_t code = lv_event_get_code(event);
    PageStruct_t* page = (PageStruct_t*)lv_event_get_user_data(event);

    if (code == USER_Event_ROTATE)
    {
        lv_disp_t* disp = lv_obj_get_disp(lv_scr_act());
        lv_disp_rot_t rotation = *(lv_disp_rot_t*)lv_event_get_param(event);
        if (rotation == lv_disp_get_rotation(NULL))
            return;

        switch (rotation)
        {
            case LV_DISP_ROT_NONE:
            {
                LCD_direction(0);
                lv_disp_set_rotation(disp, LV_DISP_ROT_NONE);
                break;
            }
            case LV_DISP_ROT_90:
            {
                LCD_direction(1);
                lv_disp_set_rotation(disp, LV_DISP_ROT_90);
                break;
            }
            case LV_DISP_ROT_180:
            {
                LCD_direction(2);
                lv_disp_set_rotation(disp, LV_DISP_ROT_180);
                break;
            }
            case LV_DISP_ROT_270:
            {
                LCD_direction(3);
                lv_disp_set_rotation(disp, LV_DISP_ROT_270);
                break;
            }
        }

        //if (disp->scr_to_load == page->screen)
        {
            page_callback(page->page_id, LV_SCR_LOAD_ANIM_FADE_IN, 0);
            lv_obj_invalidate(lv_scr_act());
        }
    }
    if (code == USER_Event_STATBAR)
    {
        status_bar_update(page);
    }
}
//static void send_event(struct _lv_timer_t *timer) {
//    PageStruct_t* page = (PageStruct_t*)timer->user_data;
//
//    lv_event_send(page->screen, LV_EVENT_REFRESH, NULL);
//}

static void page_clock_refresh(lv_event_t* event)
{
    PageStruct_t* page = (PageStruct_t*)lv_event_get_user_data(event);

    //时针、分针、秒针转动角度
    lv_img_set_angle(page->objs[page->obj_num + 2], m_curtime.Second * 60);//s秒表
    lv_img_set_angle(page->objs[page->obj_num + 1], m_curtime.Minute * 60  + m_curtime.Second);//m分钟
    lv_img_set_angle(page->objs[page->obj_num + 0], m_curtime.Hour   * 300 + m_curtime.Minute * 5);//h时
    lv_label_set_text_fmt(page->objs[page->obj_num + 3], "%02d/%2d", m_curtime.Month, m_curtime.Days);
    //lv_label_set_text_fmt(page->objs[page->obj_num + 3], "%04d", m_volval);
}

static void page_calendar_refresh(lv_event_t* event)
{
    PageStruct_t* page = (PageStruct_t*)lv_event_get_user_data(event);
    lv_obj_t* calendar = page->objs[page->obj_num];

    lv_calendar_set_today_date(calendar, m_curtime.Year, m_curtime.Month, m_curtime.Days);
    lv_calendar_set_showed_date(calendar, m_curtime.Year, m_curtime.Month);
}

static void page_horizon_refresh(lv_event_t* event)
{
    PageStruct_t* page = (PageStruct_t*)lv_event_get_user_data(event);
    lv_obj_t* angle  = page->objs[page->obj_num + 0];
    lv_obj_t* sphere = page->objs[page->obj_num + 1];

    lv_label_set_text_fmt(angle, "%d°", m_angle);
    lv_obj_set_x(sphere, m_pitch);
    lv_obj_set_y(sphere, m_roll);
}

static void location_refresh(PageStruct_t* page,
    int num_x, int num_y, 
    int ofs_x, int ofs_y)
{
    lv_obj_t** ui_Image = &page->objs[page->obj_num];

    char path[32];
    int x_item[2] = { num_x, 0 };
    int y_item[2] = { num_y, 0 };
    int x_move[2] = { ofs_x, 0};
    int y_move[2] = { ofs_y, 0 };

    if (ofs_x < 128)
    {
        x_item[1] = x_item[0] - 1;
        x_move[0] = 128 - ofs_x;
        x_move[1] = x_move[0] - TILES_WIDTH;
    }
    else
    {
        x_item[1] = x_item[0] + 1;
        x_move[0] = 128 - ofs_x;
        x_move[1] = x_move[0] + TILES_WIDTH;
    }
    if (ofs_y < 128)
    {
        y_item[1] = y_item[0] - 1;
        y_move[0] = 128 - ofs_y;
        y_move[1] = y_move[0] - TILES_HIGHT;
    }
    else
    {
        y_item[1] = y_item[0] + 1;
        y_move[0] = 128 - ofs_y;
        y_move[1] = y_move[0] + TILES_HIGHT;
    }

    sprintf(path, "0:/%d/%d/%d.hms", location_zoom, x_item[0], y_item[0]);
    lv_img_set_src(ui_Image[0], path);
    sprintf(path, "0:/%d/%d/%d.hms", location_zoom, x_item[0], y_item[1]);
    lv_img_set_src(ui_Image[1], path);
    sprintf(path, "0:/%d/%d/%d.hms", location_zoom, x_item[1], y_item[0]);
    lv_img_set_src(ui_Image[2], path);
    sprintf(path, "0:/%d/%d/%d.hms", location_zoom, x_item[1], y_item[1]);
    lv_img_set_src(ui_Image[3], path);

    lv_obj_set_pos(ui_Image[0], x_move[0], y_move[0]);
    lv_obj_set_pos(ui_Image[1], x_move[0], y_move[1]);
    lv_obj_set_pos(ui_Image[2], x_move[1], y_move[0]);
    lv_obj_set_pos(ui_Image[3], x_move[1], y_move[1]);
}

/************************************************************************/
/* Event Callback                                                       */
/************************************************************************/
static void menu_click_event_cb(lv_event_t* e)
{
    PageStruct_t* page = (PageStruct_t*)lv_event_get_user_data(e);
    if (page->page_id == PAGE_HOME)
    {
        lv_obj_t* target = lv_event_get_target(e);
        for (int i = 0; i < page->obj_num; i++)
        {
            if (page->objs[i] == target)
            {
                page_subid = i;
                page_callback(PAGE_HEART + i, LV_SCR_LOAD_ANIM_MOVE_RIGHT, true);
            }
        }
    }
    else
    {
        if (page->timer)
        {
            lv_timer_pause(page->timer);
        }
        if (page->page_id == PAGE_HEART)
        {
            lv_canvas_set_buffer(page->objs[1], &m_ClearBuf, 1, 1, LV_IMG_CF_INDEXED_1BIT);
            lv_mem_free(m_HeartBuf);
            m_HeartBuf = NULL;
        }
        page_callback(PAGE_HOME, LV_SCR_LOAD_ANIM_MOVE_LEFT, true);
    }
}

static void menu_click_event_cb2(lv_event_t* e)
{
    static int state = 0;
    lv_obj_t* act_scr = lv_scr_act();
    lv_disp_t* disp = lv_obj_get_disp(act_scr);
    if (state == 0)
    {
        state = 1;
        //LCD_direction(3);
        lv_disp_set_rotation(disp, LV_DISP_ROT_270);
    }
    else
    {
        state = 0;
        //LCD_direction(0);
        lv_disp_set_rotation(disp, LV_DISP_ROT_NONE);
    }
}

static void theme_color_event_cb(lv_event_t* e)
{
    int  cur_sel = 0;
    lv_color_t* active = lv_event_get_user_data(e);

    for (int i = 0; i < THEME_COLOR_MAX; i++)
    {
        if (active == m_colorTheme[i])
            cur_sel = i;
    }
    /*Do nothing if the container was clicked*/
    if (cur_sel == m_colorSel)
    {
        return;
    }

    if ((cur_sel >= 0) && cur_sel < THEME_COLOR_MAX && cur_sel != m_colorSel)
    {
        m_colorSel = cur_sel;
#if LV_USE_THEME_DEFAULT
        lv_theme_default_init(NULL, m_colorTheme[m_colorSel][1], m_colorTheme[m_colorSel][2], LV_THEME_DEFAULT_DARK,
            font_normal);
#endif
        if(m_charge) //charing
            lv_style_set_bg_color(&style_batval, m_colorTheme[m_colorSel][1]);
        else
            lv_style_set_bg_color(&style_batval, m_colorTheme[m_colorSel][0]);

        lv_style_set_text_color(&style_icon, m_colorTheme[m_colorSel][1]);
        lv_style_set_text_color(&style_arc,  m_colorTheme[m_colorSel][2]);
        lv_style_set_text_color(&style_charge, m_colorTheme[m_colorSel][1]);
        lv_style_set_text_color(&style_title, m_colorTheme[m_colorSel][1]);
        status_bar_update(page_focus);
    }

    LV_LOG_USER("Selected radio buttons: %d", cur_sel);
}

static void heart_refresh_timer_cb(struct _lv_timer_t* timer)
{
    PageStruct_t* page = (PageStruct_t*)timer->user_data;
    lv_obj_t* canvas = page->objs[page->obj_num];

    lv_canvas_set_buffer(page->objs[1], m_HeartBuf, HEART_WIDTH, HEART_WIDTH, LV_IMG_CF_INDEXED_1BIT);
    lv_canvas_set_palette(canvas, 0, HEART_COLOR_BG);
    lv_canvas_set_palette(canvas, 1, HEART_COLOR);

    DrawHeart(canvas);

    nHeartFrames += nHeartZoom;
    if (nHeartFrames >= 6)
        nHeartZoom = -2;
    if (nHeartFrames <= 0)
        nHeartZoom = 3;
}

static void gps_refresh_timer_cb(struct _lv_timer_t* timer)
{
    PageStruct_t* page = (PageStruct_t*)timer->user_data;
    lv_obj_t* hint_labe = page->objs[page->obj_num + 4];

    //lv_label_set_text_fmt(hint_labe, "len:%d lat:%d lon:%d", uart6_cnt, latitude, longitude);
    //location_refresh(page);

    lv_label_set_text_fmt(hint_labe, "lat:%.6f lon:%.6f\nlen:%u/%u zoom:%d\n",
        latitude_gjc, longitude_gjc, uart6_cnt[0], uart6_cnt[1], location_zoom);
}

static void location_zoom_event_cb(lv_event_t* e)
{
    PageStruct_t* page = (PageStruct_t*)lv_event_get_user_data(e);
    lv_event_code_t code = lv_event_get_code(e);
    uint32_t *key = lv_event_get_param(e);
    int32_t zoom;
    int32_t tiles_num_x;
    int32_t tiles_num_y;
    int32_t tiles_ofs_x;
    int32_t tiles_ofs_y;

    if (code == LV_EVENT_KEY && *key == LV_KEY_LEFT)
    {
        //LV_LOG_WARN("zoom up\n");
        if (location_zoom < TILES_ZOOM_MAX)
            location_zoom++;
        else
            return;
        zoom = TILES_ZOOM_MAX - location_zoom;
        tiles_num_x = (tiles_pos_x[0] >> zoom) / 256;
        tiles_num_y = (tiles_pos_y[0] >> zoom) / 256;
        tiles_ofs_x = (tiles_pos_x[0] >> zoom) % 256;
        tiles_ofs_y = (tiles_pos_y[0] >> zoom) % 256;
        location_refresh(page, tiles_num_x, tiles_num_y, tiles_ofs_x, tiles_ofs_y);
    }
    else if(code == LV_EVENT_KEY && *key == LV_KEY_RIGHT)
    {
        //LV_LOG_WARN("zoom down\n");
        if (location_zoom > TILES_ZOOM_MIN)
            location_zoom--;
        else
            return;
        zoom = TILES_ZOOM_MAX - location_zoom;
        tiles_num_x = (tiles_pos_x[0] >> zoom) / 256;
        tiles_num_y = (tiles_pos_y[0] >> zoom) / 256;
        tiles_ofs_x = (tiles_pos_x[0] >> zoom) % 256;
        tiles_ofs_y = (tiles_pos_y[0] >> zoom) % 256;
        location_refresh(page, tiles_num_x, tiles_num_y, tiles_ofs_x, tiles_ofs_y);
    }
}
/************************************************************************/
/* Status Bar                                                           */
/************************************************************************/
static void status_bar_create(PageStruct_t* page, lv_obj_t *parent)
{

    if (page->inited == 0)
    {
        UI_Status_t* stbar = &page->status_bar;
        stbar->panel = lv_obj_create(parent);
        lv_obj_set_width(stbar->panel, 54);
        lv_obj_set_height(stbar->panel, 30);
        lv_obj_set_style_radius(stbar->panel, 0, 0);    //设置圆角
        lv_obj_add_style(stbar->panel, &style_comb, 0); //将样式添加到对象中
        lv_obj_clear_flag(stbar->panel, LV_OBJ_FLAG_SCROLLABLE);

        //外框
        stbar->bat_outline = lv_obj_create(stbar->panel);
        lv_obj_set_style_border_width(stbar->bat_outline, 1, 0);    //设置border和pading
        lv_obj_set_style_pad_all(stbar->bat_outline, 0, 0);
        lv_obj_set_style_radius(stbar->bat_outline, 4, 0);    //设置圆角
        lv_obj_set_style_border_color(stbar->bat_outline, lv_color_hex(0xA0A0A0), 0); //设置颜色
        lv_obj_clear_flag(stbar->bat_outline, LV_OBJ_FLAG_SCROLLABLE);    //关闭滚动条
        lv_obj_set_size(stbar->bat_outline, OUTLINE_W, OUTLINE_H);    //设置宽高
        lv_obj_set_x(stbar->bat_outline,  4);
        lv_obj_set_y(stbar->bat_outline, -8);
        lv_obj_set_align(stbar->bat_outline, LV_ALIGN_CENTER);

        //右侧电池头
        stbar->bat_subbody = lv_obj_create(stbar->panel);
        lv_obj_set_style_radius(stbar->bat_subbody, 2, 0);    //设置圆角
        lv_obj_set_style_border_color(stbar->bat_subbody, lv_color_hex(0xA0A0A0), 0); //设置颜色
        lv_obj_clear_flag(stbar->bat_subbody, LV_OBJ_FLAG_SCROLLABLE);//关闭滚动条
        lv_obj_set_size(stbar->bat_subbody, 2, 8);
        lv_obj_set_x(stbar->bat_subbody, OUTLINE_W / 2 + 6);
        lv_obj_set_y(stbar->bat_subbody, -8);
        lv_obj_set_align(stbar->bat_subbody, LV_ALIGN_CENTER);

        //电池电量填充
        stbar->bat_backdrop = lv_obj_create(stbar->bat_outline);
        lv_obj_add_style(stbar->bat_backdrop, &style_batval, 0);
        lv_obj_set_size(stbar->bat_backdrop, (OUTLINE_W - 2) / 2, OUTLINE_H - 2); //设置宽高****
        lv_obj_align(stbar->bat_backdrop, LV_ALIGN_LEFT_MID, 0, 0);     //居中对齐
        lv_obj_clear_flag(stbar->bat_backdrop, LV_OBJ_FLAG_SCROLLABLE); //关闭滚动条

        //电池电量百分比
        stbar->bat_voltage = lv_label_create(stbar->bat_outline);
        lv_obj_add_style(stbar->bat_voltage, &style_normal, 0);
        lv_obj_align(stbar->bat_voltage, LV_ALIGN_CENTER, 0, 0);
        lv_label_set_text_fmt(stbar->bat_voltage, "%d", 50);

        //电池充电状态
        stbar->bat_charge = lv_label_create(stbar->panel);
        lv_obj_add_style(stbar->bat_charge, &style_charge, 0);
        lv_obj_set_x(stbar->bat_charge, 0 - OUTLINE_W / 2);
        lv_obj_set_y(stbar->bat_charge, -6);
        lv_obj_set_size(stbar->bat_charge, OUTLINE_H, OUTLINE_H);
        lv_obj_set_align(stbar->bat_charge, LV_ALIGN_CENTER);
        lv_label_set_text(stbar->bat_charge, m_charge ? LV_SYMBOL_CHARGE : " ");

        //GPS信号状态
        stbar->gps_signal = lv_label_create(stbar->panel);
        lv_obj_add_style(stbar->gps_signal, &style_charge, 0);
        lv_obj_set_x(stbar->gps_signal, -4 - OUTLINE_W / 2);
        lv_obj_set_y(stbar->gps_signal, 8);
        lv_obj_set_size(stbar->gps_signal, OUTLINE_H, OUTLINE_H);
        lv_obj_set_align(stbar->gps_signal, LV_ALIGN_CENTER);
        lv_label_set_text(stbar->gps_signal, m_clocksync ? LV_SYMBOL_GPS : " ");

        //当前时间
        stbar->rl_clock = lv_label_create(stbar->panel);
        lv_obj_add_style(stbar->rl_clock, &style_normal, 0);
        lv_obj_set_x(stbar->rl_clock, OUTLINE_W / 2 + 6);
        lv_obj_set_y(stbar->rl_clock, 8);
        lv_obj_set_size(stbar->rl_clock, OUTLINE_H * 4, OUTLINE_H);
        lv_obj_set_align(stbar->rl_clock, LV_ALIGN_CENTER);
        lv_label_set_text_fmt(stbar->rl_clock, "%02d:%02d", m_curtime.Hour, m_curtime.Minute);

        //状态0
        //stbar->status[0] = lv_label_create(stbar->panel);
        //lv_obj_add_style(stbar->status[0], &style_normal, 0);
        //lv_obj_set_x(stbar->status[0], OUTLINE_W / 2 + 6);
        //lv_obj_set_y(stbar->status[0], 8);
        //lv_obj_set_size(stbar->status[0], OUTLINE_H*4, OUTLINE_H);
        //lv_obj_set_align(stbar->status[0], LV_ALIGN_CENTER);
        //lv_label_set_text_fmt(stbar->status[0], "%02d:%02d", 0, 0);

    }
}

static void status_bar_update(PageStruct_t* page)
{
    lv_label_set_text(page->status_bar.bat_charge, m_charge ? LV_SYMBOL_CHARGE : " ");
    lv_label_set_text(page->status_bar.gps_signal, m_clocksync ? LV_SYMBOL_GPS : " ");
    lv_label_set_text_fmt(page->status_bar.bat_voltage, "%d", m_voltage);
    lv_label_set_text_fmt(page->status_bar.rl_clock, "%02d:%02d", m_curtime.Hour, m_curtime.Minute);
    lv_obj_set_width(page->status_bar.bat_backdrop, (OUTLINE_W - 2) * m_voltage / 100); //设置宽高
    if (m_voltage < 10)
        lv_obj_set_style_bg_color(page->status_bar.bat_backdrop, lv_color_hex(0xFF0000), 0);
    else if (m_voltage < 20)
        lv_obj_set_style_bg_color(page->status_bar.bat_backdrop, lv_color_hex(0x1D1F21), 0);
    else
        lv_obj_set_style_bg_color(page->status_bar.bat_backdrop, m_colorTheme[m_colorSel][0], 0);
}

/************************************************************************/
/* Page Create                                                          */
/************************************************************************/
static void home_create(void* data)
{
    PageStruct_t* page = (PageStruct_t*)data;
    static lv_obj_t* panel0;
    static lv_obj_t* panel1;
    static lv_obj_t* menu_title;
    static lv_obj_t* menu_btn[6];
    static lv_obj_t* menu_icon[6];
    static lv_obj_t* menu_label[6];

    if (page->inited == 0)
    {
        lv_obj_clear_flag(page->screen, LV_OBJ_FLAG_SCROLLABLE);

        panel0 = lv_obj_create(page->screen);
        lv_obj_set_height(panel0, LV_SIZE_CONTENT);
        lv_obj_set_style_pad_right(panel0, 2, 0);
        //lv_obj_set_style_pad_ver(panel0, 8, 0);

        panel1 = lv_obj_create(page->screen);
        lv_obj_set_height(panel1, LV_SIZE_CONTENT);

        status_bar_create(page, panel0);

        menu_title = lv_label_create(panel0);
        lv_label_set_recolor(menu_title, true);
        lv_label_set_text(menu_title, LV_SYMBOL_HOME " Home");
        lv_obj_add_style(menu_title, &style_title, 0);

        menu_label[0] = lv_label_create(panel1);
        lv_label_set_text(menu_label[0], "Heart");

        menu_label[1] = lv_label_create(panel1);
        //lv_obj_add_style(dsc, &style_text_muted, 0);
        lv_label_set_text(menu_label[1], "Clock");

        menu_label[2] = lv_label_create(panel1);
        lv_label_set_text(menu_label[2], "Calendar");

        menu_label[3] = lv_label_create(panel1);
        lv_label_set_text(menu_label[3], "Horizon");

        menu_label[4] = lv_label_create(panel1);
        lv_label_set_text(menu_label[4], "Location");

        menu_label[5] = lv_label_create(panel1);
        lv_label_set_text(menu_label[5], "Setting");

        menu_btn[0] = lv_btn_create(panel1);
        lv_obj_set_content_height(menu_btn[0], 26);
        //lv_obj_set_width(menu_btn[0], LV_SIZE_CONTENT);
        lv_obj_set_content_width(menu_btn[0], 20);
        lv_obj_add_event_cb(menu_btn[0], menu_click_event_cb, LV_EVENT_CLICKED, page);

        menu_icon[0] = lv_label_create(menu_btn[0]);
        //lv_obj_add_style(menu_icon[0], &style_icon2, 0);
        lv_obj_set_style_text_font(menu_icon[0], &lv_custom_icon, 0);
        lv_label_set_text(menu_icon[0], "\xEE\x98\x91");
        lv_obj_center(menu_icon[0]);

        menu_btn[1] = lv_btn_create(panel1);
        lv_obj_set_content_height(menu_btn[1], 26);
        lv_obj_set_content_width(menu_btn[1], 20);
        lv_obj_add_event_cb(menu_btn[1], menu_click_event_cb, LV_EVENT_CLICKED, page);

        menu_icon[1] = lv_label_create(menu_btn[1]);
        lv_obj_set_style_text_font(menu_icon[1], &lv_custom_icon, 0);
        lv_label_set_text(menu_icon[1], "\xEE\x98\x92");
        lv_obj_center(menu_icon[1]);

        menu_btn[2] = lv_btn_create(panel1);
        lv_obj_set_content_height(menu_btn[2], 26);
        lv_obj_set_content_width(menu_btn[2], 20);
        lv_obj_add_event_cb(menu_btn[2], menu_click_event_cb, LV_EVENT_CLICKED, page);

        menu_icon[2] = lv_label_create(menu_btn[2]);
        lv_obj_set_style_text_font(menu_icon[2], &lv_custom_icon, 0);
        lv_label_set_text(menu_icon[2], "\xEE\x98\x93");
        lv_obj_center(menu_icon[2]);

        menu_btn[3] = lv_btn_create(panel1);
        lv_obj_set_content_height(menu_btn[3], 24);
        lv_obj_set_content_width(menu_btn[3], 20);
        lv_obj_add_event_cb(menu_btn[3], menu_click_event_cb, LV_EVENT_CLICKED, page);

        menu_icon[3] = lv_label_create(menu_btn[3]);
        lv_obj_set_style_text_font(menu_icon[3], &lv_custom_icon, 0);
        lv_label_set_text(menu_icon[3], "\xEE\x98\x94");
        lv_obj_center(menu_icon[3]);

        menu_btn[4] = lv_btn_create(panel1);
        lv_obj_set_content_height(menu_btn[4], 24);
        lv_obj_set_content_width(menu_btn[4], 20);
        lv_obj_add_event_cb(menu_btn[4], menu_click_event_cb, LV_EVENT_CLICKED, page);

        menu_icon[4] = lv_label_create(menu_btn[4]);
        lv_obj_set_style_text_font(menu_icon[4], &lv_custom_icon, 0);
        lv_label_set_text(menu_icon[4], "\xEE\x98\x95");
        lv_obj_center(menu_icon[4]);

        menu_btn[5] = lv_btn_create(panel1);
        lv_obj_set_content_height(menu_btn[5], 24);
        lv_obj_set_content_width(menu_btn[5], 20);
        lv_obj_add_event_cb(menu_btn[5], menu_click_event_cb, LV_EVENT_CLICKED, page);

        menu_icon[5] = lv_label_create(menu_btn[5]);
        lv_obj_set_style_text_font(menu_icon[5], &lv_custom_icon, 0);
        lv_label_set_text(menu_icon[5], "\xEE\x98\x98");
        lv_obj_center(menu_icon[5]);

        page->objs[page->obj_num++] = menu_btn[0];
        page->objs[page->obj_num++] = menu_btn[1];
        page->objs[page->obj_num++] = menu_btn[2];
        page->objs[page->obj_num++] = menu_btn[3];
        page->objs[page->obj_num++] = menu_btn[4];
        page->objs[page->obj_num++] = menu_btn[5];

        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_ROTATE, page);
        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_STATBAR, page);
    }
    page->inited = 1;

    static lv_coord_t grid_main_col_dsc[] = { LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST };
    static lv_coord_t grid_main_row_dsc[] = { LV_GRID_CONTENT, LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST };
    lv_obj_set_grid_dsc_array(page->screen, grid_main_col_dsc, grid_main_row_dsc);

    /*Create the top panel*/
    static lv_coord_t grid_0_col_dsc[] = { LV_GRID_FR(1), LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST };
    static lv_coord_t grid_0_row_dsc[] = { LV_GRID_CONTENT, /**/
                                           LV_GRID_TEMPLATE_LAST
    };

    /*Create the top panel*/
    static lv_coord_t grid_1_col_dsc[] = { LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST };
    static lv_coord_t grid_1_row_dsc[] = { LV_GRID_CONTENT, /**/
                                       LV_GRID_CONTENT, /**/
                                       3,
                                       LV_GRID_CONTENT, /**/
                                       LV_GRID_CONTENT, /**/
                                       LV_GRID_CONTENT, /**/
                                       LV_GRID_TEMPLATE_LAST
    };

    lv_obj_set_grid_dsc_array(panel0, grid_0_col_dsc, grid_0_col_dsc);
    lv_obj_set_grid_dsc_array(panel1, grid_1_col_dsc, grid_1_row_dsc);

    lv_obj_set_grid_cell(panel0,     LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1);
    lv_obj_set_grid_cell(menu_title, LV_GRID_ALIGN_START , 0, 1, LV_GRID_ALIGN_CENTER,  0, 1);
    lv_obj_set_grid_cell(page->status_bar.panel, LV_GRID_ALIGN_END, 1, 1, LV_GRID_ALIGN_CENTER, 0, 1);

    lv_obj_set_grid_cell(panel1, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 1, 1);
    lv_obj_set_grid_cell(menu_btn[0], LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1);
    lv_obj_set_grid_cell(menu_btn[1], LV_GRID_ALIGN_CENTER, 1, 1, LV_GRID_ALIGN_CENTER, 0, 1);
    lv_obj_set_grid_cell(menu_btn[2], LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_CENTER, 0, 1);
    lv_obj_set_grid_cell(menu_btn[3], LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 3, 1);
    lv_obj_set_grid_cell(menu_btn[4], LV_GRID_ALIGN_CENTER, 1, 1, LV_GRID_ALIGN_CENTER, 3, 1);
    lv_obj_set_grid_cell(menu_btn[5], LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_CENTER, 3, 1);

    lv_obj_set_grid_cell(menu_label[0], LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_START, 1, 1);
    lv_obj_set_grid_cell(menu_label[1], LV_GRID_ALIGN_CENTER, 1, 1, LV_GRID_ALIGN_START, 1, 1);
    lv_obj_set_grid_cell(menu_label[2], LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_START, 1, 1);
    lv_obj_set_grid_cell(menu_label[3], LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_START, 4, 1);
    lv_obj_set_grid_cell(menu_label[4], LV_GRID_ALIGN_CENTER, 1, 1, LV_GRID_ALIGN_START, 4, 1);
    lv_obj_set_grid_cell(menu_label[5], LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_START, 4, 1);
}

static void heart_create(void* data)
{
    PageStruct_t* page = (PageStruct_t*)data;
    static lv_draw_label_dsc_t label_dsc;
    static lv_obj_t* menu_btn[1];
    static lv_obj_t* menu_labe[1];
    static lv_obj_t* canvas;

    if (!page->inited)
    {
        m_colorBack.full  = 0;
        m_colorPoint.full = 1;

        status_bar_create(page, page->screen);

        lv_draw_label_dsc_init(&label_dsc);
        label_dsc.color = lv_palette_main(LV_PALETTE_ORANGE);

        //m_HeartBuf = lv_mem_alloc(HEART_WIDTH * HEART_WIDTH * sizeof(lv_color_int_t));
        //memset(m_HeartBuf+240*20, 0x5a, sizeof(m_HeartBuf)/2);
        canvas = lv_canvas_create(page->screen);
        lv_canvas_set_buffer(canvas, &m_ClearBuf, 1, 1, LV_IMG_CF_INDEXED_1BIT);
        lv_canvas_set_palette(canvas, 0, HEART_COLOR_BG);
        lv_canvas_set_palette(canvas, 1, HEART_COLOR);
        lv_obj_set_style_radius(canvas, 8, 0);    //设置圆角
        lv_obj_align(canvas, LV_ALIGN_CENTER, 0, 0);
        lv_obj_center(canvas);

        menu_btn[0] = lv_btn_create(page->screen);
        lv_obj_set_height(menu_btn[0], LV_SIZE_CONTENT);
        lv_obj_set_width(menu_btn[0], LV_SIZE_CONTENT);
        //lv_obj_set_align(menu_btn[0], LV_ALIGN_TOP_LEFT);
        lv_obj_add_event_cb(menu_btn[0], menu_click_event_cb, LV_EVENT_CLICKED, page);

        menu_labe[0] = lv_label_create(menu_btn[0]);
        lv_label_set_text(menu_labe[0], LV_SYMBOL_HOME);
        lv_obj_center(menu_labe[0]);

        page->objs[page->obj_num++] = menu_btn[0];
        page->objs[page->obj_num]   = canvas;

        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_ROTATE, page);
        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_STATBAR, page);

        /**<每个1秒发一次LV_EVENT_REFRESH事件*/
        page->timer = lv_timer_create(heart_refresh_timer_cb, 250, page);
    }

    page->inited = 1;

    /*Create the top panel*/
    static lv_coord_t grid_0_col_dsc[5] = { LV_GRID_FR(1), LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST, LV_GRID_TEMPLATE_LAST, LV_GRID_TEMPLATE_LAST };
    static lv_coord_t grid_0_row_dsc[5] = { 2,
                                           LV_GRID_CONTENT, /**/
                                           LV_GRID_CONTENT, /**/
                                           LV_GRID_TEMPLATE_LAST
    };

    if (lv_disp_get_rotation(NULL) == LV_DISP_ROT_NONE || lv_disp_get_rotation(NULL) == LV_DISP_ROT_180)
    {
        grid_0_col_dsc[0] = 2;
        grid_0_col_dsc[1] = LV_GRID_CONTENT;
        grid_0_col_dsc[2] = LV_GRID_FR(1);
        grid_0_col_dsc[3] = LV_GRID_CONTENT;
        grid_0_col_dsc[4] = LV_GRID_TEMPLATE_LAST;

        grid_0_row_dsc[0] = 2;
        grid_0_row_dsc[1] = LV_GRID_CONTENT;
        grid_0_row_dsc[2] = LV_GRID_CONTENT;
        grid_0_row_dsc[3] = LV_GRID_TEMPLATE_LAST;
        grid_0_row_dsc[4] = LV_GRID_TEMPLATE_LAST;

        lv_obj_set_grid_dsc_array(page->screen, grid_0_col_dsc, grid_0_row_dsc);
        lv_obj_set_grid_cell(menu_btn[0],     LV_GRID_ALIGN_START,  1, 1, LV_GRID_ALIGN_CENTER, 1, 1);
        lv_obj_set_grid_cell(page->status_bar.panel, LV_GRID_ALIGN_CENTER, 3, 1, LV_GRID_ALIGN_CENTER, 1, 1);
        lv_obj_set_grid_cell(canvas,          LV_GRID_ALIGN_CENTER, 0, 4, LV_GRID_ALIGN_CENTER, 2, 1);
    }
    else
    {
        grid_0_col_dsc[0] =  2;
        grid_0_col_dsc[1] = LV_GRID_CONTENT;
        grid_0_col_dsc[2] = LV_GRID_CONTENT;
        grid_0_col_dsc[3] = LV_GRID_TEMPLATE_LAST;

        grid_0_row_dsc[0] = 2;
        grid_0_row_dsc[1] = LV_GRID_CONTENT;
        grid_0_row_dsc[2] = LV_GRID_FR(1);
        grid_0_row_dsc[3] = LV_GRID_CONTENT;
        grid_0_row_dsc[4] = LV_GRID_TEMPLATE_LAST;

        lv_obj_set_grid_dsc_array(page->screen, grid_0_col_dsc, grid_0_row_dsc);
        lv_obj_set_grid_cell(menu_btn[0],     LV_GRID_ALIGN_START,  1, 1, LV_GRID_ALIGN_START , 1, 1);
        lv_obj_set_grid_cell(page->status_bar.panel, LV_GRID_ALIGN_CENTER, 1, 1, LV_GRID_ALIGN_CENTER, 3, 1);
        lv_obj_set_grid_cell(canvas,          LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_CENTER, 0, 4);
    }
}

static void clock_create(void* data)
{
    PageStruct_t* page = (PageStruct_t*)data;
    const int16_t digit_ofs = 102;
    const int16_t digit_sin = digit_ofs / 2;
    const int16_t digit_cos = digit_ofs * 433U / 500U;
    const int16_t digit_x[12] = {  digit_sin,  digit_cos,  digit_ofs,  digit_cos,  digit_sin, 0,
                                  -digit_sin, -digit_cos, -digit_ofs, -digit_cos, -digit_sin, 0 };
    const int16_t digit_y[12] = { -digit_cos, -digit_sin, 0,  digit_sin,  digit_cos,  digit_ofs,
                                   digit_cos,  digit_sin, 0, -digit_sin, -digit_cos, -digit_ofs };

    static lv_obj_t* panel0;
    static lv_obj_t* menu_labe[1];
    static lv_obj_t* menu_btn[1];

    if (!page->inited)
    {
        panel0 = lv_obj_create(page->screen);
        lv_obj_set_width(panel0,  240);
        lv_obj_set_height(panel0, 240);
        lv_obj_add_style(panel0, &style_comb, 0); //将样式添加到对象中
        lv_obj_clear_flag(panel0, LV_OBJ_FLAG_SCROLLABLE);

        menu_btn[0] = lv_btn_create(page->screen);
        lv_obj_set_height(menu_btn[0], LV_SIZE_CONTENT);
        lv_obj_set_width(menu_btn[0], LV_SIZE_CONTENT);
        lv_obj_set_align(menu_btn[0], LV_ALIGN_TOP_LEFT);//居中控件
        lv_obj_add_event_cb(menu_btn[0], menu_click_event_cb, LV_EVENT_CLICKED, page);

        menu_labe[0] = lv_label_create(menu_btn[0]);
        lv_label_set_text(menu_labe[0], LV_SYMBOL_HOME);
        lv_obj_center(menu_labe[0]);

        LV_IMG_DECLARE(lv_img_clock);
        LV_IMG_DECLARE(lv_img_hour);
        LV_IMG_DECLARE(lv_img_min);
        LV_IMG_DECLARE(lv_img_sec);
        lv_obj_t* ui_Image2 = lv_img_create(panel0);
        lv_img_set_src(ui_Image2, &lv_img_clock);
        //lv_img_set_src(ui_Image2, "0:/clock.bin");
        lv_obj_set_width(ui_Image2, LV_SIZE_CONTENT);  /// 240
        lv_obj_set_height(ui_Image2, LV_SIZE_CONTENT);   /// 240
        lv_obj_set_align(ui_Image2, LV_ALIGN_CENTER);//居中控件
        lv_obj_clear_flag(ui_Image2, LV_OBJ_FLAG_SCROLLABLE);   /// Flags
        lv_obj_add_flag(ui_Image2, LV_OBJ_FLAG_ADV_HITTEST);    /// Flags
        //lv_obj_add_style(ui_Image2, &style_text_muted, 0);

        /*Create an Arc*/
        lv_obj_t* arc = lv_arc_create(panel0);
        lv_obj_set_size(arc, 240, 240);
        lv_arc_set_bg_angles(arc, 0, 360);
		lv_obj_add_style(arc, &style_arc, LV_PART_MAIN | LV_STATE_DEFAULT);
		lv_obj_add_style(arc, &style_arc, LV_PART_INDICATOR | LV_STATE_DEFAULT);
        //lv_obj_set_style_arc_width(arc, 4, LV_PART_MAIN | LV_STATE_DEFAULT);
        //lv_obj_set_style_arc_width(arc, 4, LV_PART_INDICATOR | LV_STATE_DEFAULT);
        //lv_obj_set_style_arc_color(arc, m_colorTheme[m_colorSel][2], LV_PART_INDICATOR | LV_STATE_DEFAULT);
        lv_obj_remove_style(arc, NULL, LV_PART_KNOB);
        lv_obj_clear_flag(arc, LV_OBJ_FLAG_CLICKABLE);  /*To not allow adjusting by click*/
        lv_arc_set_value(arc, 100);
        lv_obj_center(arc);

        for (int i = 0; i < 12; i++)
        {
            lv_obj_t* lable = lv_label_create(panel0);
            lv_obj_set_width(lable, LV_SIZE_CONTENT);  /// 1
            lv_obj_set_height(lable, LV_SIZE_CONTENT);   /// 1
            lv_obj_set_x(lable, digit_x[i]);
            lv_obj_set_y(lable, digit_y[i]);
            lv_obj_set_align(lable, LV_ALIGN_CENTER);
            lv_obj_add_style(lable, &style_icon, 0);
            lv_label_set_text_fmt(lable, "%d", i + 1);
        }

        lv_obj_t* label0 = lv_label_create(panel0);
        lv_obj_set_width(label0, LV_SIZE_CONTENT);  /// 1
        lv_obj_set_height(label0, LV_SIZE_CONTENT);   /// 1
        lv_obj_set_x(label0, 0);
        lv_obj_set_y(label0, 82);
        lv_obj_set_align(label0, LV_ALIGN_CENTER);
        lv_obj_add_style(label0, &style_icon, 0);
        lv_label_set_text(label0, "01/08");

        lv_obj_t* hour_img = lv_img_create(panel0);//时针
        lv_img_set_src(hour_img, &lv_img_hour);
        lv_obj_set_width(hour_img, LV_SIZE_CONTENT);/// 14
        lv_obj_set_height(hour_img, LV_SIZE_CONTENT);/// 44
        lv_obj_set_x(hour_img, 0);
        lv_obj_set_y(hour_img, -26);
        lv_obj_set_align(hour_img, LV_ALIGN_CENTER);
        lv_obj_add_flag(hour_img, LV_OBJ_FLAG_ADV_HITTEST);   /// Flags
        lv_obj_clear_flag(hour_img, LV_OBJ_FLAG_SCROLLABLE);    /// Flags
        lv_img_set_pivot(hour_img, 6, 57); //setting reference point, default as left-top

        lv_obj_t* min_img = lv_img_create(panel0);//分针
        lv_img_set_src(min_img, &lv_img_min);
        lv_obj_set_width(min_img, LV_SIZE_CONTENT);/// 15
        lv_obj_set_height(min_img, LV_SIZE_CONTENT);/// 83
        lv_obj_set_x(min_img, 0);
        lv_obj_set_y(min_img, -34);
        lv_obj_set_align(min_img, LV_ALIGN_CENTER);
        lv_obj_add_flag(min_img, LV_OBJ_FLAG_ADV_HITTEST);    /// Flags
        lv_obj_clear_flag(min_img, LV_OBJ_FLAG_SCROLLABLE);   /// Flags
        lv_img_set_pivot(min_img, 6, 73);

        lv_obj_t* sec_img = lv_img_create(panel0);//秒针
        lv_img_set_src(sec_img, &lv_img_sec);
        lv_obj_set_width(sec_img, LV_SIZE_CONTENT);/// 14
        lv_obj_set_height(sec_img, LV_SIZE_CONTENT);/// 44
        lv_obj_set_x(sec_img, 0);
        lv_obj_set_y(sec_img, -39);
        lv_obj_set_align(sec_img, LV_ALIGN_CENTER);
        lv_obj_add_flag(sec_img, LV_OBJ_FLAG_ADV_HITTEST);    /// Flags
        lv_obj_clear_flag(sec_img, LV_OBJ_FLAG_SCROLLABLE);   /// Flags
        lv_img_set_pivot(sec_img, 6, 83);

        lv_img_set_angle(sec_img, 0);//s秒表
        lv_img_set_angle(min_img, 0);//m分钟
        lv_img_set_angle(hour_img, 0);//h时

        status_bar_create(page, page->screen);

        //lv_obj_add_event_cb(page->screen, page_user_event_cb, LV_EVENT_SIZE_CHANGED, page);
        page->objs[page->obj_num++]   = menu_btn[0];
        page->objs[page->obj_num + 0] = hour_img;
        page->objs[page->obj_num + 1] = min_img;
        page->objs[page->obj_num + 2] = sec_img;
        page->objs[page->obj_num + 3] = label0;

        /* DEBUG:每个1秒发一次LV_EVENT_REFRESH事件 */
        //page->timer = lv_timer_create(send_event, 1000, page);
        //lv_timer_pause(page->timer);

        /* 设置LV_EVENT_REFRESH事件的回调 */
        lv_obj_add_event_cb(page->screen, page_clock_refresh, LV_EVENT_REFRESH, page);
        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_ROTATE, page);
        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_STATBAR, page);
    }

    page->inited = 1;

    /* Create the top panel             +-------------------------------------------------> x     */
    static lv_coord_t grid_col_dsc[] = { LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST, LV_GRID_TEMPLATE_LAST, LV_GRID_TEMPLATE_LAST, LV_GRID_TEMPLATE_LAST };
    static lv_coord_t grid_row_dsc[] = { LV_GRID_CONTENT, /**/
                                         LV_GRID_FR(1), /**/
                                         LV_GRID_CONTENT, /**/
                                         LV_GRID_TEMPLATE_LAST,
                                         LV_GRID_TEMPLATE_LAST,
                                         LV_GRID_TEMPLATE_LAST,
    };                               //\/y

    if (lv_disp_get_rotation(NULL) == LV_DISP_ROT_NONE || lv_disp_get_rotation(NULL) == LV_DISP_ROT_180)
    {
        grid_col_dsc[0] = 48;
        grid_col_dsc[1] = LV_GRID_FR(1);
        grid_col_dsc[2] = 48;
        grid_col_dsc[3] = LV_GRID_TEMPLATE_LAST;

        grid_row_dsc[0] = 2;
        grid_row_dsc[1] = LV_GRID_CONTENT;
        grid_row_dsc[2] = LV_GRID_FR(1);
        grid_row_dsc[3] = LV_GRID_TEMPLATE_LAST;
        lv_obj_set_grid_dsc_array(page->screen, grid_col_dsc, grid_row_dsc);

        lv_obj_set_grid_cell(menu_btn[0], LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 1, 1);
        lv_obj_set_grid_cell(panel0,      LV_GRID_ALIGN_CENTER, 0, 3, LV_GRID_ALIGN_CENTER, 1, 2);
        lv_obj_set_grid_cell(page->status_bar.panel, LV_GRID_ALIGN_END, 2, 1, LV_GRID_ALIGN_START, 1, 1);
    }
    else
    {
        grid_col_dsc[0] = 48;
        grid_col_dsc[1] = LV_GRID_FR(1);
        grid_col_dsc[2] = 48;
        grid_col_dsc[3] = LV_GRID_TEMPLATE_LAST;
        grid_col_dsc[4] = LV_GRID_TEMPLATE_LAST;

        grid_row_dsc[0] =  2;
        grid_row_dsc[1] = 16;
        grid_row_dsc[2] = LV_GRID_FR(1);
        grid_row_dsc[3] = LV_GRID_TEMPLATE_LAST;

        lv_obj_set_grid_dsc_array(page->screen, grid_col_dsc, grid_row_dsc);
        lv_obj_set_grid_cell(menu_btn[0],     LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 1, 1);
        lv_obj_set_grid_cell(panel0,          LV_GRID_ALIGN_CENTER, 0, 3, LV_GRID_ALIGN_CENTER, 0, 3);
        lv_obj_set_grid_cell(page->status_bar.panel, LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_CENTER, 1, 1);
    }
}

static void calendar_create(void* data)
{
    PageStruct_t* page = (PageStruct_t*)data;
    static lv_obj_t* menu_btn[1];
    static lv_obj_t* menu_label[1];
    static lv_obj_t* calendar;
    static lv_obj_t* date_labe;

    if (!page->inited)
    {
        menu_btn[0] = lv_btn_create(page->screen);
        lv_obj_set_height(menu_btn[0], LV_SIZE_CONTENT);
        //lv_obj_set_width(menu_btn[0], LV_SIZE_CONTENT);
        lv_obj_set_width(menu_btn[0], LV_SIZE_CONTENT);
        lv_obj_add_event_cb(menu_btn[0], menu_click_event_cb, LV_EVENT_CLICKED, page);

        menu_label[0] = lv_label_create(menu_btn[0]);
        lv_label_set_text(menu_label[0], LV_SYMBOL_HOME);
        lv_obj_center(menu_label[0]);

        calendar = lv_calendar_create(page->screen);
        lv_obj_set_size(calendar, 220, 220);
        lv_obj_align(calendar, LV_ALIGN_CENTER, 0, 27);
        if (m_clocksync)
        {
            lv_calendar_set_today_date(calendar, m_curtime.Year, m_curtime.Month, m_curtime.Days);
            lv_calendar_set_showed_date(calendar, m_curtime.Year, m_curtime.Month);
        }
        else
        {
            lv_calendar_set_today_date(calendar, 2023, 11, 05);
            lv_calendar_set_showed_date(calendar, 2023, 11);
        }
        lv_obj_t* head = lv_calendar_header_arrow_create(calendar);
        //lv_obj_t* head = lv_calendar_header_dropdown_create(calendar);

        lv_obj_set_height(head->spec_attr->children[0], 22);
        lv_obj_set_height(head->spec_attr->children[2], 22);
        lv_obj_set_height(head, 32);

        /*Highlight a few days*/
        static lv_calendar_date_t highlighted_days[3];       /*Only its pointer will be saved so should be static*/
        highlighted_days[0].year = 2023;
        highlighted_days[0].month = 11;
        highlighted_days[0].day = 05;

        highlighted_days[1].year = 2024;
        highlighted_days[1].month = 11;
        highlighted_days[1].day = 05;

        highlighted_days[2].year = 2025;
        highlighted_days[2].month = 11;
        highlighted_days[2].day = 05;

        lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3);

        date_labe = lv_label_create(page->screen);
        lv_label_set_text(date_labe, "date info ....\n... ...");
        lv_obj_center(date_labe);

        status_bar_create(page, page->screen);

        lv_group_remove_obj(calendar);
        //lv_obj_add_event_cb(page->screen, page_user_event_cb, LV_EVENT_SIZE_CHANGED, page);
        page->objs[page->obj_num++] = menu_btn[0];
        page->objs[page->obj_num++] = head->spec_attr->children[0];
        page->objs[page->obj_num++] = head->spec_attr->children[2];
        page->objs[page->obj_num++] = lv_calendar_get_btnmatrix(calendar);
        page->objs[page->obj_num] = calendar;

        lv_obj_add_event_cb(page->screen, page_calendar_refresh, LV_EVENT_REFRESH, page);
        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_ROTATE, page);
        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_STATBAR, page);
    }

    page->inited = 1;

    /* Create the top panel             +-------------------------------------------------> x     */
    static lv_coord_t grid_col_dsc[5] = { LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST, LV_GRID_TEMPLATE_LAST, LV_GRID_TEMPLATE_LAST, LV_GRID_TEMPLATE_LAST };
    static lv_coord_t grid_row_dsc[6] = { LV_GRID_CONTENT, /**/
                                         LV_GRID_FR(1), /**/
                                         LV_GRID_CONTENT, /**/
                                         LV_GRID_TEMPLATE_LAST,
                                         LV_GRID_TEMPLATE_LAST,
                                         LV_GRID_TEMPLATE_LAST,
    };                               //\/y

    if (lv_disp_get_rotation(NULL) == LV_DISP_ROT_NONE || lv_disp_get_rotation(NULL) == LV_DISP_ROT_180)
    {
        grid_col_dsc[0] = 2;
        grid_col_dsc[1] = LV_GRID_FR(1);
        grid_col_dsc[2] = LV_GRID_FR(1);
        grid_col_dsc[3] = 2;
        grid_col_dsc[4] = LV_GRID_TEMPLATE_LAST;

        grid_row_dsc[0] = 2;
        grid_row_dsc[1] = LV_GRID_CONTENT;
        grid_row_dsc[2] = LV_GRID_CONTENT;
        grid_row_dsc[3] = LV_GRID_FR(1);
        grid_row_dsc[4] = LV_GRID_TEMPLATE_LAST;

        lv_obj_set_grid_dsc_array(page->screen, grid_col_dsc, grid_row_dsc);

        lv_obj_set_grid_cell(menu_btn[0], LV_GRID_ALIGN_START,  1, 1, LV_GRID_ALIGN_CENTER, 1, 1);
        lv_obj_set_grid_cell(calendar,    LV_GRID_ALIGN_CENTER, 0, 4, LV_GRID_ALIGN_CENTER, 2, 1);
        lv_obj_set_grid_cell(date_labe,   LV_GRID_ALIGN_START,  1, 3, LV_GRID_ALIGN_START,  3, 1);
        lv_obj_set_grid_cell(page->status_bar.panel, LV_GRID_ALIGN_END, 2, 1, LV_GRID_ALIGN_START, 1, 1);
    }
    else
    {
        grid_col_dsc[0] = 2;
        grid_col_dsc[1] = LV_GRID_FR(1);
        grid_col_dsc[2] = LV_GRID_CONTENT;
        grid_col_dsc[3] = 2;
        grid_col_dsc[4] = LV_GRID_TEMPLATE_LAST;

        grid_row_dsc[0] = 2;
        grid_row_dsc[1] = LV_GRID_CONTENT;
        grid_row_dsc[2] = LV_GRID_FR(1);
        grid_row_dsc[3] = LV_GRID_CONTENT;
        grid_row_dsc[4] = 2;
        grid_row_dsc[5] = LV_GRID_TEMPLATE_LAST;

        lv_obj_set_grid_dsc_array(page->screen, grid_col_dsc, grid_row_dsc);

        lv_obj_set_grid_cell(menu_btn[0], LV_GRID_ALIGN_START,  1, 1, LV_GRID_ALIGN_START, 1, 1);
        lv_obj_set_grid_cell(calendar,    LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_CENTER, 1, 3);
        lv_obj_set_grid_cell(date_labe,   LV_GRID_ALIGN_START,  1, 1, LV_GRID_ALIGN_CENTER, 2, 1);
        lv_obj_set_grid_cell(page->status_bar.panel, LV_GRID_ALIGN_CENTER, 1, 1, LV_GRID_ALIGN_START, 3, 1);
    }
}

static void horizon_create(void* data)
{
    PageStruct_t* page = (PageStruct_t*)data;
    static lv_obj_t* panel0;
    static lv_obj_t* menu_labe[2];
    static lv_obj_t* menu_btn[1];

    if (!page->inited)
    {
        menu_btn[0] = lv_btn_create(page->screen);
        lv_obj_set_height(menu_btn[0], LV_SIZE_CONTENT);
        lv_obj_set_width(menu_btn[0], LV_SIZE_CONTENT);
        lv_obj_set_align(menu_btn[0], LV_ALIGN_TOP_LEFT);//居中控件
        lv_obj_add_event_cb(menu_btn[0], menu_click_event_cb, LV_EVENT_CLICKED, page);

        menu_labe[0] = lv_label_create(menu_btn[0]);
        lv_label_set_text(menu_labe[0], LV_SYMBOL_HOME);
        lv_obj_center(menu_labe[0]);

        LV_FONT_DECLARE(lv_oft_18);
        menu_labe[1] = lv_label_create(page->screen);
        lv_obj_set_style_text_font(menu_labe[1], font_large, LV_STATE_DEFAULT);
        lv_label_set_text(menu_labe[1], "0°");
        lv_obj_center(menu_labe[1]);

        panel0 = lv_obj_create(page->screen);
        lv_obj_set_width(panel0, 240);
        lv_obj_set_height(panel0, 240);
        lv_obj_add_style(panel0, &style_comb, 0); //将样式添加到对象中
        lv_obj_clear_flag(panel0, LV_OBJ_FLAG_SCROLLABLE);

        LV_IMG_DECLARE(lv_horizon);
        LV_IMG_DECLARE(lv_sphere);
        lv_obj_t* ui_Image = lv_img_create(panel0);
        lv_img_set_src(ui_Image, &lv_horizon);
        //lv_img_set_src(ui_Image, "0:/lv_horizon.png");
        lv_obj_set_width(ui_Image, LV_SIZE_CONTENT);  /// 240
        lv_obj_set_height(ui_Image, LV_SIZE_CONTENT);   /// 240
        lv_obj_set_align(ui_Image, LV_ALIGN_CENTER);//居中控件
        lv_obj_clear_flag(ui_Image, LV_OBJ_FLAG_SCROLLABLE);   /// Flags
        lv_obj_add_flag(ui_Image, LV_OBJ_FLAG_ADV_HITTEST);    /// Flags
        lv_obj_add_style(ui_Image, &style_comb, 0);

        for (int i = 1; i <= 5; i++)
        {
            lv_obj_t* lable = lv_label_create(panel0);
            lv_obj_set_width(lable, LV_SIZE_CONTENT);  /// 1
            lv_obj_set_height(lable, LV_SIZE_CONTENT);   /// 1
            lv_obj_set_x(lable, 20*i+2);
            lv_obj_set_y(lable,  0);
            lv_obj_set_align(lable, LV_ALIGN_CENTER);
            lv_obj_add_style(lable, &style_normal, 0);
            lv_label_set_text_fmt(lable, "%d", i * 10);
        }

        lv_obj_t* ui_sphere = lv_img_create(panel0);
        lv_img_set_src(ui_sphere, &lv_sphere);
        //lv_img_set_src(ui_sphere, "0:/lv_horizon.png");
        //lv_obj_set_width(ui_sphere, 48);  /// 240
        //lv_obj_set_height(ui_sphere, 48);   /// 240
        lv_obj_set_align(ui_sphere, LV_ALIGN_CENTER);//居中控件
        lv_obj_clear_flag(ui_sphere, LV_OBJ_FLAG_SCROLLABLE);   /// Flags
        lv_obj_add_flag(ui_sphere, LV_OBJ_FLAG_ADV_HITTEST);    /// Flags
        lv_obj_add_style(ui_sphere, &style_comb, 0);

//         lv_obj_t* hour_img = lv_img_create(panel0);//时针
//         lv_img_set_src(hour_img, &lv_img_hour);
//         lv_obj_set_width(hour_img, LV_SIZE_CONTENT);/// 14
//         lv_obj_set_height(hour_img, LV_SIZE_CONTENT);/// 44
//         lv_obj_set_x(hour_img, 0);
//         lv_obj_set_y(hour_img, -26);
//         lv_obj_set_align(hour_img, LV_ALIGN_CENTER);
//         lv_obj_add_flag(hour_img, LV_OBJ_FLAG_ADV_HITTEST);   /// Flags
//         lv_obj_clear_flag(hour_img, LV_OBJ_FLAG_SCROLLABLE);    /// Flags
//         lv_img_set_pivot(hour_img, 6, 57); //setting reference point, default as left-top

        status_bar_create(page, page->screen);

        //lv_obj_add_event_cb(page->screen, page_user_event_cb, LV_EVENT_SIZE_CHANGED, page);
        page->objs[page->obj_num++] = menu_btn[0];
        page->objs[page->obj_num]   = menu_labe[1];
        page->objs[page->obj_num+1] = ui_sphere;

        lv_obj_add_event_cb(page->screen, page_horizon_refresh, LV_EVENT_REFRESH, page);
        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_ROTATE, page);
        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_STATBAR, page);
    }

    page->inited = 1;

    /* Create the top panel             +-------------------------------------------------> x     */
    static lv_coord_t grid_col_dsc[] = { LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST, LV_GRID_TEMPLATE_LAST, LV_GRID_TEMPLATE_LAST, LV_GRID_TEMPLATE_LAST };
    static lv_coord_t grid_row_dsc[] = { LV_GRID_CONTENT, /**/
                                         LV_GRID_FR(1), /**/
                                         LV_GRID_CONTENT, /**/
                                         LV_GRID_TEMPLATE_LAST,
                                         LV_GRID_TEMPLATE_LAST,
                                         LV_GRID_TEMPLATE_LAST,
    };                               //\/y

    //if (lv_disp_get_rotation(NULL) == LV_DISP_ROT_NONE || lv_disp_get_rotation(NULL) == LV_DISP_ROT_180)
    {
        grid_col_dsc[0] = 48;
        grid_col_dsc[1] = LV_GRID_FR(1);
        grid_col_dsc[2] = 48;
        grid_col_dsc[3] = LV_GRID_TEMPLATE_LAST;

        grid_row_dsc[0] = 2;
        grid_row_dsc[1] = LV_GRID_CONTENT;
        grid_row_dsc[2] = 2;
        grid_row_dsc[3] = LV_GRID_FR(1);
        grid_row_dsc[4] = LV_GRID_TEMPLATE_LAST;
        lv_obj_set_grid_dsc_array(page->screen, grid_col_dsc, grid_row_dsc);

        lv_obj_set_grid_cell(menu_btn[0],  LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 1, 1);
        lv_obj_set_grid_cell(menu_labe[1], LV_GRID_ALIGN_CENTER, 0, 3, LV_GRID_ALIGN_END, 1, 2);
        lv_obj_set_grid_cell(panel0, LV_GRID_ALIGN_CENTER, 0, 3, LV_GRID_ALIGN_START, 3, 1);
        lv_obj_set_grid_cell(page->status_bar.panel, LV_GRID_ALIGN_END, 2, 1, LV_GRID_ALIGN_START, 1, 1);
    }
    /*
    else
    {
        grid_col_dsc[0] = 48;
        grid_col_dsc[1] = LV_GRID_FR(1);
        grid_col_dsc[2] = 48;
        grid_col_dsc[3] = LV_GRID_TEMPLATE_LAST;
        grid_col_dsc[4] = LV_GRID_TEMPLATE_LAST;

        grid_row_dsc[0] = 2;
        grid_row_dsc[1] = 16;
        grid_row_dsc[2] = LV_GRID_FR(1);
        grid_row_dsc[3] = LV_GRID_TEMPLATE_LAST;

        lv_obj_set_grid_dsc_array(page->screen, grid_col_dsc, grid_row_dsc);
        lv_obj_set_grid_cell(menu_btn[0], LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 1, 1);
        lv_obj_set_grid_cell(panel0, LV_GRID_ALIGN_CENTER, 0, 3, LV_GRID_ALIGN_CENTER, 0, 3);
        lv_obj_set_grid_cell(page->status_bar.panel, LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_CENTER, 1, 1);
    }
    */
}

static void location_create(void* data)
{
    PageStruct_t* page = (PageStruct_t*)data;
    static lv_obj_t* panel0;
    static lv_obj_t* menu_btn[1];
    static lv_obj_t* menu_label[1];
    static lv_obj_t* hint_labe;
    static lv_obj_t* ui_Image[4];

    if (!page->inited)
    {
        lv_obj_clear_flag(page->screen, LV_OBJ_FLAG_SCROLLABLE);

        panel0 = lv_obj_create(page->screen);
        lv_obj_set_width(panel0, LV_HOR_RES);
        lv_obj_set_height(panel0, LV_VER_RES);
        //lv_obj_add_style(panel0, &style_comb, 0); //将样式添加到对象中
        lv_obj_clear_flag(panel0, LV_OBJ_FLAG_SCROLLABLE);

        status_bar_create(page, page->screen);

        menu_btn[0] = lv_btn_create(page->screen);
        //lv_obj_add_state(menu_btn[0], LV_STATE_DISABLED);
        lv_obj_set_height(menu_btn[0], LV_SIZE_CONTENT);
        //lv_obj_set_width(menu_btn[0], LV_SIZE_CONTENT);
        lv_obj_set_width(menu_btn[0], LV_SIZE_CONTENT);

        menu_label[0] = lv_label_create(menu_btn[0]);
        lv_label_set_text(menu_label[0], LV_SYMBOL_HOME);
        lv_obj_center(menu_label[0]);

        ui_Image[0] = lv_img_create(panel0);
        lv_img_set_src(ui_Image[0], "0:/13/6660/3421.hms");
        lv_obj_set_align(ui_Image[0], LV_ALIGN_CENTER);//居中控件
        lv_obj_clear_flag(ui_Image[0], LV_OBJ_FLAG_SCROLLABLE);   /// Flags
        lv_obj_add_flag(ui_Image[0], LV_OBJ_FLAG_ADV_HITTEST);    /// Flags

        ui_Image[1] = lv_img_create(panel0);
        //lv_img_set_src(ui_Image[1], "0:/13/6660/3422.sjp");
        lv_obj_set_align(ui_Image[1], LV_ALIGN_CENTER);//居中控件
        lv_obj_clear_flag(ui_Image[1], LV_OBJ_FLAG_SCROLLABLE);   /// Flags
        lv_obj_add_flag(ui_Image[1], LV_OBJ_FLAG_ADV_HITTEST);    /// Flags

        ui_Image[2] = lv_img_create(panel0);
        //lv_img_set_src(ui_Image[2], "0:/13/6660/3423.sjp");
        lv_obj_set_align(ui_Image[2], LV_ALIGN_CENTER);//居中控件
        lv_obj_clear_flag(ui_Image[2], LV_OBJ_FLAG_SCROLLABLE);   /// Flags
        lv_obj_add_flag(ui_Image[2], LV_OBJ_FLAG_ADV_HITTEST);    /// Flags

        ui_Image[3] = lv_img_create(panel0);
        //lv_img_set_src(ui_Image[3], "0:/13/6660/3424.sjp");
        lv_obj_set_align(ui_Image[3], LV_ALIGN_CENTER);//居中控件
        lv_obj_clear_flag(ui_Image[3], LV_OBJ_FLAG_SCROLLABLE);   /// Flags
        lv_obj_add_flag(ui_Image[3], LV_OBJ_FLAG_ADV_HITTEST);    /// Flags

        lv_obj_set_pos(ui_Image[0], 30      ,      -60);
        lv_obj_set_pos(ui_Image[1], 30      , 256 - 60);
        lv_obj_set_pos(ui_Image[2], 30 - 256,     - 60);
        lv_obj_set_pos(ui_Image[3], 30 - 256, 256 - 60);

        hint_labe = lv_label_create(page->screen);
        lv_label_set_long_mode(hint_labe, LV_LABEL_LONG_WRAP); /*Circular scroll*/
        lv_obj_set_width(hint_labe, 220);
        lv_obj_set_height(hint_labe, 32);
        lv_label_set_text(hint_labe, "...E ...N");
        lv_obj_center(hint_labe);

        page->objs[page->obj_num++]   = menu_btn[0];
        page->objs[page->obj_num + 0] = ui_Image[0];
        page->objs[page->obj_num + 1] = ui_Image[1];
        page->objs[page->obj_num + 2] = ui_Image[2];
        page->objs[page->obj_num + 3] = ui_Image[3];
        page->objs[page->obj_num + 4] = hint_labe;

        lv_group_set_editing(lv_group_get_default(), true);

        /**<每个1秒发一次LV_EVENT_REFRESH事件*/
        page->timer = lv_timer_create(gps_refresh_timer_cb, 1000, page);
        lv_timer_pause(page->timer);

        lv_obj_add_event_cb(menu_btn[0], menu_click_event_cb, LV_EVENT_CLICKED, page);
        lv_obj_add_event_cb(menu_btn[0], location_zoom_event_cb, LV_EVENT_KEY, page);
        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_ROTATE, page);
        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_STATBAR, page);
    }
    page->inited = 1;

    if (lv_disp_get_rotation(NULL) == LV_DISP_ROT_NONE || lv_disp_get_rotation(NULL) == LV_DISP_ROT_180)
    {
        lv_obj_set_width(hint_labe, 220);
        lv_obj_set_height(hint_labe, 280);
    }
    else
    {
        lv_obj_set_width(hint_labe, 300);
        lv_obj_set_height(hint_labe, 200);
    }

    /*Create the top panel*/
    static lv_coord_t grid_col_dsc[] = { 2, LV_GRID_FR(1), LV_GRID_FR(1), 2, LV_GRID_TEMPLATE_LAST };
    static lv_coord_t grid_row_dsc[] = { 2, /**/
                                         LV_GRID_CONTENT, /**/
                                         LV_GRID_CONTENT, /**/
                                         LV_GRID_TEMPLATE_LAST
    };

    lv_obj_set_grid_dsc_array(page->screen, grid_col_dsc, grid_row_dsc);

    lv_obj_set_grid_cell(menu_btn[0], LV_GRID_ALIGN_START,  1, 1, LV_GRID_ALIGN_START, 1, 1);
    lv_obj_set_grid_cell(panel0,      LV_GRID_ALIGN_CENTER, 0, 4, LV_GRID_ALIGN_START, 0, 4);
    lv_obj_set_grid_cell(hint_labe,   LV_GRID_ALIGN_START,  1, 2, LV_GRID_ALIGN_START, 2, 1);
    lv_obj_set_grid_cell(page->status_bar.panel, LV_GRID_ALIGN_END, 2, 1, LV_GRID_ALIGN_START, 1, 1);
}

static void setting_create(void* data)
{
    PageStruct_t* page = (PageStruct_t*)data;
    static lv_obj_t* panel;
    static lv_obj_t* menu_btn[1];
    static lv_obj_t* menu_label[2];
    static lv_obj_t* title_label[8];
    static lv_obj_t* item_line[8];
    static lv_obj_t* rot_switch;
    static lv_obj_t* light_slider;
    static lv_obj_t* light_lable;
    static lv_obj_t* scroff_drop;
    static lv_obj_t* theme_chk[4];
    static lv_point_t line_points[8][2] = {
        {{ 5,  38 }, { 212,  38 } },
        {{ 5,  76 }, { 212,  76 } },
        {{ 5, 116 }, { 212, 116 } },
        {{ 5, 154 }, { 212, 154 } },
    };
    uint32_t i;

    if (!page->inited)
    {
        lv_obj_clear_flag(page->screen, LV_OBJ_FLAG_SCROLLABLE);

        status_bar_create(page, page->screen);

        menu_btn[0] = lv_btn_create(page->screen);
        //lv_obj_add_state(menu_btn[0], LV_STATE_DISABLED);
        lv_obj_set_height(menu_btn[0], LV_SIZE_CONTENT);
        //lv_obj_set_width(menu_btn[0], LV_SIZE_CONTENT);
        lv_obj_set_width(menu_btn[0], LV_SIZE_CONTENT);
        lv_obj_add_event_cb(menu_btn[0], menu_click_event_cb, LV_EVENT_CLICKED, page);

        menu_label[0] = lv_label_create(menu_btn[0]);
        lv_label_set_text(menu_label[0], LV_SYMBOL_HOME);
        lv_obj_center(menu_label[0]);

        menu_label[1] = lv_label_create(page->screen);
        lv_label_set_text(menu_label[1], "Setting");
        lv_obj_center(menu_label[1]);

        panel = lv_obj_create(page->screen);
        //lv_obj_set_width(panel, 54);
        //lv_obj_set_height(panel, 30);
        lv_obj_set_style_radius(panel, 8, 0);    //设置圆角
        //lv_obj_add_style(panel, &style_comb, 0); //将样式添加到对象中
        lv_obj_clear_flag(panel, LV_OBJ_FLAG_SCROLLABLE);

        title_label[0] = lv_label_create(panel);
        lv_label_set_text(title_label[0], "Rotation:");
        rot_switch = lv_switch_create(panel);
        lv_obj_set_height(rot_switch, 24);

        line_points[0][1].x = LV_HOR_RES - 28;
        item_line[0] = lv_line_create(panel);
        lv_line_set_points(item_line[0], line_points[0], 2);     /*Set the points*/
        lv_obj_add_style(item_line[0], &style_line, 0);
        lv_obj_center(item_line[0]);

        title_label[1] = lv_label_create(panel);
        lv_label_set_text(title_label[1], "Light:");
        light_slider = lv_slider_create(panel);
        lv_obj_center(light_slider);
        lv_slider_set_range(light_slider, 2, 10);
        lv_obj_set_width(light_slider, 136);
        //lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);

        line_points[1][1].x = LV_HOR_RES - 28;
        item_line[1] = lv_line_create(panel);
        lv_line_set_points(item_line[1], line_points[1], 2);     /*Set the points*/
        lv_obj_add_style(item_line[1], &style_line, 0);
        lv_obj_center(item_line[1]);

        /*Create a normal drop down list*/
        title_label[2] = lv_label_create(panel);
        lv_label_set_text(title_label[2], "Screen Off:");
        scroff_drop = lv_dropdown_create(panel);
        lv_dropdown_set_options(scroff_drop, "10s\n"
            "15s\n"
            "30s\n"
            "60s\n"
            "Never");

        lv_obj_set_width(scroff_drop, 80);
        lv_obj_set_height(scroff_drop, 32);
        lv_obj_align(scroff_drop, LV_ALIGN_TOP_MID, 0, 20);

        line_points[2][1].x = LV_HOR_RES - 28;
        item_line[2] = lv_line_create(panel);
        lv_line_set_points(item_line[2], line_points[2], 2);     /*Set the points*/
        lv_obj_add_style(item_line[2], &style_line, 0);
        lv_obj_center(item_line[2]);

        title_label[3] = lv_label_create(panel);
        lv_label_set_text(title_label[3], "Theme:");

        for (i = 0; i < THEME_COLOR_MAX; i++)
        {
            theme_chk[i] = lv_btn_create(panel);
            lv_obj_set_style_bg_color(theme_chk[i], m_colorTheme[i][1], 0);
            lv_obj_set_style_bg_color(theme_chk[i], m_colorTheme[i][1], LV_STATE_FOCUS_KEY);
            lv_obj_set_style_radius(theme_chk[i], LV_RADIUS_CIRCLE, 0);
            //lv_obj_set_style_opa(theme_chk[i], LV_OPA_TRANSP, 0);
            lv_obj_set_size(theme_chk[i], 20, 20);
            lv_obj_add_event_cb(theme_chk[i], theme_color_event_cb, LV_EVENT_CLICKED, m_colorTheme[i]);
            lv_obj_clear_flag(theme_chk[i], LV_OBJ_FLAG_SCROLL_ON_FOCUS);
        }

        page->objs[page->obj_num++] = menu_btn[0];
        page->objs[page->obj_num++] = rot_switch;
        page->objs[page->obj_num++] = light_slider;
        page->objs[page->obj_num++] = scroff_drop;
        for (i = 0; i < THEME_COLOR_MAX; i++)
        {
            page->objs[page->obj_num++] = theme_chk[i];
        }

        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_ROTATE, page);
    }
    page->inited = 1;

    /*Create the top panel*/
    static lv_coord_t grid_col_dsc[] = { 2, LV_GRID_FR(1), LV_GRID_CONTENT, LV_GRID_FR(1), 2, LV_GRID_TEMPLATE_LAST };
    static lv_coord_t grid_row_dsc[] = { 2, /**/
                                         LV_GRID_CONTENT, /**/
                                         2,
                                         LV_GRID_FR(1), /**/
                                         LV_GRID_TEMPLATE_LAST
    };

    static lv_coord_t grid_col_sub[] = { LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST };
    static lv_coord_t grid_row_sub[] = { 32, /**/
                                         32, /**/
                                         32, /**/
                                         24, /**/
                                         20, /**/
                                         LV_GRID_TEMPLATE_LAST
    };

    lv_obj_set_grid_dsc_array(page->screen, grid_col_dsc, grid_row_dsc);

    lv_obj_set_width(panel, LV_HOR_RES - 4);
    lv_obj_set_height(panel, 240);
    lv_obj_set_grid_cell(menu_btn[0], LV_GRID_ALIGN_START, 1, 1, LV_GRID_ALIGN_START, 1, 1);
    lv_obj_set_grid_cell(menu_label[1], LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_CENTER, 1, 1);
    lv_obj_set_grid_cell(page->status_bar.panel, LV_GRID_ALIGN_END, 3, 1, LV_GRID_ALIGN_START, 1, 1);
    lv_obj_set_grid_cell(panel, LV_GRID_ALIGN_CENTER, 0, 5, LV_GRID_ALIGN_START, 3, 1);

    lv_obj_set_grid_dsc_array(panel, grid_col_sub, grid_row_sub);
    lv_obj_set_grid_cell(title_label[0], LV_GRID_ALIGN_START, 0, 2, LV_GRID_ALIGN_CENTER, 0, 1);
    lv_obj_set_grid_cell(title_label[1], LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_CENTER, 1, 1);
    lv_obj_set_grid_cell(title_label[2], LV_GRID_ALIGN_START, 0, 2, LV_GRID_ALIGN_CENTER, 2, 1);
    lv_obj_set_grid_cell(title_label[3], LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_CENTER, 3, 1);
    lv_obj_set_grid_cell(rot_switch,   LV_GRID_ALIGN_END, 2, 2, LV_GRID_ALIGN_CENTER, 0, 1);
    lv_obj_set_grid_cell(light_slider, LV_GRID_ALIGN_END, 1, 3, LV_GRID_ALIGN_CENTER, 1, 1);
    lv_obj_set_grid_cell(scroff_drop,  LV_GRID_ALIGN_END, 2, 2, LV_GRID_ALIGN_CENTER, 2, 1);
    lv_obj_set_grid_cell(theme_chk[0], LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 4, 1);
    lv_obj_set_grid_cell(theme_chk[1], LV_GRID_ALIGN_CENTER, 1, 1, LV_GRID_ALIGN_CENTER, 4, 1);
    lv_obj_set_grid_cell(theme_chk[2], LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_CENTER, 4, 1);
    lv_obj_set_grid_cell(theme_chk[3], LV_GRID_ALIGN_CENTER, 3, 1, LV_GRID_ALIGN_CENTER, 4, 1);
}

static void other_create(void* data)
{
    PageStruct_t* page = (PageStruct_t*)data;
    static lv_obj_t* menu_btn[2];
    static lv_obj_t* menu_label[2];
    static lv_obj_t* hint_labe;

    if (!page->inited)
    {
        status_bar_create(page, page->screen);

        menu_btn[0] = lv_btn_create(page->screen);
        lv_obj_set_height(menu_btn[0], LV_SIZE_CONTENT);
        //lv_obj_set_width(menu_btn[0], LV_SIZE_CONTENT);
        lv_obj_set_width(menu_btn[0], LV_SIZE_CONTENT);
        lv_obj_add_event_cb(menu_btn[0], menu_click_event_cb, LV_EVENT_CLICKED, page);

        menu_label[0] = lv_label_create(menu_btn[0]);
        lv_label_set_text(menu_label[0], LV_SYMBOL_HOME);
        lv_obj_center(menu_label[0]);

        menu_btn[1] = lv_btn_create(page->screen);
        lv_obj_set_height(menu_btn[1], LV_SIZE_CONTENT);
        lv_obj_set_width(menu_btn[1], LV_SIZE_CONTENT);
        lv_obj_add_event_cb(menu_btn[1], menu_click_event_cb2, LV_EVENT_CLICKED, page);

        menu_label[1] = lv_label_create(menu_btn[1]);
        lv_label_set_text(menu_label[1], LV_SYMBOL_REFRESH);
        lv_obj_center(menu_label[1]);

        hint_labe = lv_label_create(page->screen);
        lv_label_set_long_mode(hint_labe, LV_LABEL_LONG_SCROLL_CIRCULAR);     /*Circular scroll*/
        lv_obj_set_height(hint_labe, 150);
        lv_label_set_text(hint_labe, "Features under development...");
        lv_obj_center(hint_labe);

        //lv_obj_add_event_cb(page->screen, page_user_event_cb, LV_EVENT_SIZE_CHANGED, page);
        page->obj_num = 0;
        page->objs[page->obj_num++] = menu_btn[0];
        page->objs[page->obj_num++] = menu_btn[1];

        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_ROTATE, page);
        lv_obj_add_event_cb(page->screen, page_user_event_cb, USER_Event_STATBAR, page);
    }

    page->inited = 1;

    /*Create the top panel*/
    static lv_coord_t grid_col_dsc[4] = { LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST, LV_GRID_TEMPLATE_LAST };
    static lv_coord_t grid_row_dsc[4] = { LV_GRID_CONTENT, /**/
                                       LV_GRID_FR(1), /**/
                                       LV_GRID_TEMPLATE_LAST,
                                       LV_GRID_TEMPLATE_LAST
    };

    if (lv_disp_get_rotation(NULL) == LV_DISP_ROT_NONE || lv_disp_get_rotation(NULL) == LV_DISP_ROT_180)
    {
        grid_col_dsc[0] = LV_GRID_FR(1);
        grid_col_dsc[1] = LV_GRID_FR(1);
        grid_col_dsc[2] = LV_GRID_FR(1);
        grid_col_dsc[3] = LV_GRID_TEMPLATE_LAST;

        grid_row_dsc[0] = LV_GRID_CONTENT;
        grid_row_dsc[1] = LV_GRID_FR(1);
        grid_row_dsc[2] = LV_GRID_TEMPLATE_LAST;

        lv_obj_set_grid_dsc_array(page->screen, grid_col_dsc, grid_row_dsc);

        lv_obj_set_grid_cell(menu_btn[0], LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1);
        lv_obj_set_grid_cell(menu_btn[1], LV_GRID_ALIGN_CENTER, 1, 1, LV_GRID_ALIGN_CENTER, 0, 1);
        lv_obj_set_grid_cell(hint_labe, LV_GRID_ALIGN_CENTER, 0, 3, LV_GRID_ALIGN_CENTER, 1, 1);
        lv_obj_set_grid_cell(page->status_bar.panel, LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_CENTER, 0, 1);
    }
    else
    {
        grid_col_dsc[0] = LV_GRID_CONTENT;
        grid_col_dsc[1] = LV_GRID_FR(1);
        grid_col_dsc[2] = LV_GRID_TEMPLATE_LAST;

        grid_row_dsc[0] = LV_GRID_FR(1);
        grid_row_dsc[1] = LV_GRID_FR(1);
        grid_row_dsc[2] = LV_GRID_CONTENT;
        grid_row_dsc[3] = LV_GRID_TEMPLATE_LAST;
        lv_obj_set_grid_dsc_array(page->screen, grid_col_dsc, grid_row_dsc);

        lv_obj_set_grid_cell(menu_btn[0], LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 0, 1);
        lv_obj_set_grid_cell(menu_btn[1], LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 1, 1);
        lv_obj_set_grid_cell(hint_labe,   LV_GRID_ALIGN_CENTER, 1, 1, LV_GRID_ALIGN_CENTER, 0, 3);
        lv_obj_set_grid_cell(page->status_bar.panel, LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 2, 1);
    }
}

static void calendar_event_cb(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * ta = lv_event_get_user_data(e);
    lv_obj_t * obj = lv_event_get_current_target(e);
    if(code == LV_EVENT_VALUE_CHANGED) {
        lv_calendar_date_t d;
        lv_calendar_get_pressed_date(obj, &d);
        char buf[32];
        lv_snprintf(buf, sizeof(buf), "%02d.%02d.%d", d.day, d.month, d.year);
        lv_textarea_set_text(ta, buf);

        lv_obj_del(calendar);
        calendar = NULL;
        lv_obj_clear_flag(lv_layer_top(), LV_OBJ_FLAG_CLICKABLE);
        lv_obj_set_style_bg_opa(lv_layer_top(), LV_OPA_TRANSP, 0);
    }
}

/************************************************************************/
/* GLOBAL FUNCTIONS                                                     */
/************************************************************************/
void lv_demo_widgets(void)
{
    font_large  = LV_FONT_DEFAULT;
    font_normal = LV_FONT_DEFAULT;

    lv_coord_t tab_h;
    { /* disp_size == DISP_SMALL */
        tab_h = 45;
#if LV_FONT_MONTSERRAT_18
        font_large = &lv_font_montserrat_18;
#else
        LV_LOG_WARN("LV_FONT_MONTSERRAT_18 is not enabled for the widgets demo. Using LV_FONT_DEFAULT instead.");
#endif
#if LV_FONT_MONTSERRAT_12
        font_normal = &lv_font_montserrat_12;
#else
        LV_LOG_WARN("LV_FONT_MONTSERRAT_12 is not enabled for the widgets demo. Using LV_FONT_DEFAULT instead.");
#endif
    }

#if LV_USE_THEME_DEFAULT
    lv_theme_default_init(NULL, m_colorTheme[m_colorSel][1], m_colorTheme[m_colorSel][2], LV_THEME_DEFAULT_DARK,
        font_normal);
#endif

    lv_style_init(&style_text_muted);
    lv_style_set_text_opa(&style_text_muted, LV_OPA_0);

    lv_style_init(&style_title);
    lv_style_set_text_font(&style_title, font_large);
    lv_style_set_text_color(&style_title, m_colorTheme[m_colorSel][1]);

    lv_style_init(&style_normal);
    lv_style_set_text_font(&style_normal, &lv_font_montserrat_12);
    lv_style_init(&style_charge);
    lv_style_set_text_font(&style_charge, &lv_font_montserrat_12);
    lv_style_set_text_color(&style_charge, m_colorTheme[m_colorSel][1]);

    lv_style_init(&style_icon);
    lv_style_set_text_color(&style_icon, m_colorTheme[m_colorSel][1]);
    lv_style_set_text_font(&style_icon, font_large);

    lv_style_init(&style_arc);
    lv_style_set_arc_width(&style_arc, 4);
    lv_style_set_arc_color(&style_arc, m_colorTheme[m_colorSel][2]);

    LV_FONT_DECLARE(lv_custom_font);
    //lv_style_init(&style_znch);
    //lv_style_set_text_font(&style_znch, &lv_custom_font);
    //lv_obj_add_style(label, LV_LABEL_PART_MAIN, &style_znch);

    lv_style_init(&style_comb);  //初始化style
    lv_style_set_bg_opa(&style_comb, LV_OPA_TRANSP);
    lv_style_set_border_side(&style_comb, LV_BORDER_SIDE_NONE); //设置样式边框显示范围
    lv_style_set_border_width(&style_comb, 0);                  //设置样式边框宽度

    lv_style_init(&style_line);  //初始化style
    lv_style_set_line_color(&style_line, m_colorTheme[m_colorSel][0]);
    lv_style_set_line_rounded(&style_line, true);

    lv_style_init(&style_batval);
    lv_style_set_outline_width(&style_batval, 0);
    lv_style_set_outline_pad(&style_batval, 0);
    lv_style_set_border_width(&style_batval, 0);
    lv_style_set_bg_color(&style_batval, m_colorTheme[m_colorSel][0]); //设置背景色
    lv_style_set_border_width(&style_batval, 0);
    lv_style_set_radius(&style_batval, 3);    //设置圆角


    tv = lv_scr_act();
    group_default = lv_group_get_default();

    USER_Event_ROTATE  = lv_event_register_id();
    USER_Event_STATBAR = lv_event_register_id();

    INIT_LIST_HEAD(&page_list);

    page_add(&page_home);
    page_add(&page_heart);
    page_add(&page_clock);
    page_add(&page_calendar);
    page_add(&page_horizon);
    page_add(&page_location);
    page_add(&page_setting);
    page_callback(PAGE_HOME, LV_SCR_LOAD_ANIM_MOVE_LEFT, true);
}

void lv_demo_widgets_close(void)
{
    /*Delete all animation*/
    lv_anim_del(NULL, NULL);

    lv_obj_clean(lv_scr_act());

    lv_style_reset(&style_text_muted);
    lv_style_reset(&style_title);
    lv_style_reset(&style_icon);
}

void lv_gui_refresh(void)
{
    int rotation = m_rotation;
    if (!(page_focus->features & FEATRUE_ROTATION))
        rotation = LV_DISP_ROT_NONE;
    if (rotation != lv_disp_get_rotation(NULL))
    {
        switch (rotation)
        {
            case LV_DISP_ROT_NONE:
            {
                LCD_direction(0);
                lv_disp_set_rotation(NULL, LV_DISP_ROT_NONE);
                break;
            }
            case LV_DISP_ROT_90:
            {
                LCD_direction(1);
                lv_disp_set_rotation(NULL, LV_DISP_ROT_90);
                break;
            }
            case LV_DISP_ROT_180:
            {
                LCD_direction(2);
                lv_disp_set_rotation(NULL, LV_DISP_ROT_180);
                break;
            }
            case LV_DISP_ROT_270:
            {
                LCD_direction(3);
                lv_disp_set_rotation(NULL, LV_DISP_ROT_270);
                break;
            }
        }

        if (page_focus && page_focus->screen)
        {
            //lv_event_send(page_focus->screen, USER_Event_ROTATE, &m_rotation);
            page_callback(page_focus->page_id, LV_SCR_LOAD_ANIM_FADE_IN, 0);
            //lv_obj_invalidate(lv_scr_act());
        }
    }
    if (m_second != m_curtime.Second)
    {
        m_second = m_curtime.Second;

        if (page_clock.screen)
        {
            lv_event_send(page_clock.screen, LV_EVENT_REFRESH, NULL);
        }
        if (page_calendar.screen && m_today != m_curtime.Days)
        {
            m_today = m_curtime.Days;
            lv_event_send(page_calendar.screen, LV_EVENT_REFRESH, NULL);
        }

        if (m_curtime.Second == 0 && page_focus && page_focus->screen)
        {
            lv_event_send(page_focus->screen, USER_Event_STATBAR, NULL);
        }
    }
    if (m_batFlag != ((uint16_t)m_charge << 8) | (uint16_t)m_voltage)
    {
        m_batFlag = ((uint16_t)m_charge << 8) | (uint16_t)m_voltage;
        if (page_focus && page_focus->screen)
        {
            lv_event_send(page_focus->screen, USER_Event_STATBAR, NULL);
        }
    }
	
    if (page_focus == &page_horizon)
    {
        lv_event_send(page_horizon.screen, LV_EVENT_REFRESH, NULL);
    }
    if (page_focus == &page_location)
    {
        if(tiles_pos_x[0] != tiles_pos_x[1] || tiles_pos_y[0] != tiles_pos_y[1])
        {
            tiles_pos_x[0] = tiles_pos_x[1];
            tiles_pos_y[0] = tiles_pos_y[1];

            int zoom = TILES_ZOOM_MAX - location_zoom;
            int tiles_num_x = (tiles_pos_x[0] >> zoom) / 256;
            int tiles_num_y = (tiles_pos_y[0] >> zoom) / 256;
            int tiles_ofs_x = (tiles_pos_x[0] >> zoom) % 256;
            int tiles_ofs_y = (tiles_pos_y[0] >> zoom) % 256;
            location_refresh(page_focus, tiles_num_x, tiles_num_y, tiles_ofs_x, tiles_ofs_y);
        }
        //lv_label_set_text(page_focus->objs[page_focus->obj_num], uart6_data);
    }
}

void lv_clock_update(NmeaTime_T* time)
{
    m_clocksync =1;
    UTC2Local_Time(time, 8, &m_curtime);
}

void lv_gui_set_battery_charge(uint32_t charging)
{
    if (charging == m_charge)
        return;

    //save
    m_charge = charging;
}

void lv_gui_set_battery_voltage(uint32_t voltage)
{
    if (voltage == m_voltage)
        return;

    //save
    m_voltage = voltage;
}

void lv_gui_set_rotation(lv_disp_rot_t rotation)
{
    m_rotation = rotation;
}

void lv_gui_set_gyro(int32_t angle, int32_t pitch, int32_t roll)
{
    m_angle = angle;
    m_pitch = pitch;
    m_roll  = roll;
}

void lv_gui_set_title(uint32_t pos_x, uint32_t pos_y)
{
    tiles_pos_x[1] = pos_x;
    tiles_pos_y[1] = pos_y;
}

int lv_get_location_zoom(void)
{
    return location_zoom;
}

#endif
